String.Replace ignoring case

前端 未结 17 750
野趣味
野趣味 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 19:42

    Extensions make our lives easier:

    static public class StringExtensions
    {
        static public string ReplaceInsensitive(this string str, string from, string to)
        {
            str = Regex.Replace(str, from, to, RegexOptions.IgnoreCase);
            return str;
        }
    }
    

提交回复
热议问题