zoukankan      html  css  js  c++  java
  • String Replace 不区分大小写的方法

    在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属性不区分大小写.

  • 相关阅读:
    Code review
    一点心得
    有关双向追踪性的一点感觉
    测试用例分析的一点心得
    js简单的抽屉菜单
    新的感受
    linux的VPS如何分区
    PHP中Unicode转码和解码的实现
    xampp安装及配置
    js Unicode编码转换
  • 原文地址:https://www.cnblogs.com/springyangwc/p/1948425.html
Copyright © 2011-2022 走看看