在C#写代码时发现Replace没有像compare一样有区分大小对比的方法,  所以我就自己写了一个方法ReplaceStr

如下:

   private string ReplaceStr(string str, string key, string value,bool IgnoreCase)
        {
            string newstr = str.Replace(key, value);

            int i = newstr.IndexOf(key, StringComparison.OrdinalIgnoreCase);

            if (i > 0&&IgnoreCase)
            {
                key = newstr.Substring(i, key.Length);
                return ReplaceStr(newstr, key, value,IgnoreCase);
            }
            else
            {
                return newstr;
            }

        }

主要用到的还是 
newstr.IndexOf(string, StringComparison.OrdinalIgnoreCase)有StringComparison.OrdinalIgnoreCase属性不区分大小写.

相关文章:

  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
  • 2022-02-24
  • 2022-12-23
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
相关资源
相似解决方案