如何替换字符串中的单词

Nov*_*eMe 2 c# string replace

这是一个非常基本的问题,但我不确定为什么它不起作用.我有代码,其中'和'可以用'And','和'等方式编写,我想用','替换它'

我试过这个:

and.Replace("and".ToUpper(),",");
Run Code Online (Sandbox Code Playgroud)

但这不起作用,任何其他方式来做到这一点或使其工作?

Nev*_*ver 6

你应该看看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, ",");
Run Code Online (Sandbox Code Playgroud)