String.Replace Method
定义
命名空间:System
-
Assemblies:
System.Runtime.dll, mscorlib.dll, netstandard.dll
返回一个新字符串,其中已将当前字符串中的指定 Unicode 字符或 String 的所有匹配项替换为其他指定的 Unicode 字符或 String
Replace(String, String)返回一个新字符串,其中当前实例中出现的所有指定字符串都替换为另一个指定的字符串。
此方法执行序号 (区分大小写和不区分区域性的) 搜索以查找
oldValue
解决方法
使用 Regex.Replace 来解决忽略大小写的替换问题
Replace(String, String, String, RegexOptions)
在指定的输入字符串内,使用指定的替换字符串替换与指定正则表达式匹配的所有字符串。 指定的选项将修改匹配操作。
例子如下:
class Program
{
static void Main()
{
string input = "hello WoRlD";
string result =
Regex.Replace(input, "world", "csharp", RegexOptions.IgnoreCase);
Console.WriteLine(result); // prints "hello csharp"
}
}