我在c#代码中有以下问题。边界字符不工作在c#
class Program
{
static void Main(string[] args)
{
string line="have a nice day with nice(songs)";
string [email protected]"\bnice\b";
string replaced_line=Regex.Replace(line, pattern, "Good", RegexOptions.IgnoreCase);
}
}
输出 - :有很好的(歌曲)的好日子
以上输出是罚款。但下面的代码是不是更换
class Program
{
static void Main(string[] args)
{
string line="have a nice day with nice(songs)";
string to_replace="nice";
string replaced_line=Regex.Replace(line, @"\b"+to_replace+"\b", "Good", RegexOptions.IgnoreCase);
}
}
输出 - :有一个愉快的一天漂亮(听歌)
它不更换
任何人都可以请帮助我。
排印错误:缺少'@' - '“\ b “'不同于'@”\ b“'。 –
你可以请重复代码与更改 – Axs
@ Manas看到我的回答 –