簡體   English   中英

string.replace()無法與xml字符串一起使用

[英]string.replace() not working with xml string

我已經閱讀了所有類似的問題,並采取了相應的行動。 但是仍然無法弄清楚我的代碼出了什么問題。

這是我的代碼,非常簡單。 (我知道這不是有效的XML。僅用於示例)。

string replacement = "TimeSheetsReplaced";
string word = "TimeSheets";
string result = "<?xml version=\"1.0\" encoding=\"utf-16\"?><DisplayName>Timesheets</DisplayName>"; 
result = result.Replace("<DisplayName>" + word + "</DisplayName>", "<DisplayName>" + replacement + "</DisplayName>");

結果字符串保持未放置狀態。 我究竟做錯了什么??

TimeSheets != Timesheets

外殼不匹配

這是因為您的字符串包含Timesheets ,但您正在尋找TimeSheets (大寫S )。

用你的話說,TimeSheets有大S,串有小s

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM