我有一个名为"hello world“的字符串
我需要把"world“改成"csharp”
为此,我使用:
string.Replace("World", "csharp");但是结果是,我没有把字符串替换掉。原因是区分大小写。原始字符串包含"World“,而我正在尝试替换"world”。
有没有办法避免在string.Replace方法中区分大小写?
发布于 2013-10-13 08:40:40
扩展让我们的生活更轻松:
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;
}
}https://stackoverflow.com/questions/6275980
复制相似问题