String.Replace ignoring case

前端 未结 17 795
野趣味
野趣味 2020-11-29 19:03

I have a string called \"hello world\"

I need to replace the word \"world\" to \"csharp\"

for this I use:

string.Replace(\"World\", \"csharp\         


        
17条回答
  •  情话喂你
    2020-11-29 20:01

    (Edited: wasn't aware of the `naked link' problem, sorry about that)

    Taken from here:

    string myString = "find Me and replace ME";
    string strReplace = "me";
    myString = Regex.Replace(myString, "me", strReplace, RegexOptions.IgnoreCase);
    

    Seems you are not the first to complain of the lack of case insensitive string.Replace.

提交回复
热议问题