这是一个非常基本的问题,但我不确定为什么它不起作用。我有可以用“和”,“和”等任何方式编写“和”的代码,我想将其替换为“,”

我尝试了这个:

and.Replace("and".ToUpper(),",");


但这是行不通的,还有其他方法可以做到或使其起作用吗?

最佳答案

您应该检查Regex类

http://msdn.microsoft.com/en-us/library/xwewhkd1.aspx

using System.Text.RegularExpressions;

Regex re = new Regex("\band\b", RegexOptions.IgnoreCase);

string and = "This is my input string with and string in between.";

re.Replace(and, ",");

关于c# - 如何替换字符串中的单词,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12522896/

10-16 15:05