我想在字符串"输入"中替换" fword"作为情况不敏感。
while (FilteredWords.Any(Input.Contains))
{
foreach (string fWord in FilteredWords)
{
Input = Input.Replace(fWord, "****");
}
}
(FilteredWords是字符串的列表,输入是"清洁"的字符串)它起作用,但是案件敏感。如何使Ford Case更换时不敏感?
如果重复问题的答案对您没有帮助,则是您的情况中的代码(请注意,我删除了while
循环 - 如果外壳是不同的,则该条件是错误的,并且您也不需要它):
foreach (string fWord in FilteredWords)
{
Input = Regex.Replace(Input, fWord, "****", RegexOptions.IgnoreCase);
}
例如,下面的代码
string fWord = "abc";
input = "AbC";
input = Regex.Replace(input, fWord, "****", RegexOptions.IgnoreCase);
产生值****
。