Replace found there is no way to distinguish Like compare the size of the contrast at the time of writing C # code, so I wrote a method ReplaceStr
as follows:
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;
}
}
The main use of or
newstr.IndexOf (string, StringComparison.OrdinalIgnoreCase) have StringComparison.OrdinalIgnoreCase property is not case sensitive.
Reproduced in: https: //www.cnblogs.com/springyangwc/archive/2011/01/31/1948425.html