C#中的字符串操作错误

Jayashree Subramanian

实际上,我想替换句子中的整个单词。但这包含和替换函数替换子字符串

例如:一个男人与一个{令人不快的女人|令人反感的女人}

我只想替换这整个词,男人……不是女人。请帮助我……在此先感谢!

if(Init.SpintexEditorPropertyMain.SpinContent.Contains(spinkey) && spinkey != string.Empty)
{
       Init.SpintexEditorPropertyMain.SpinContent = Init.SpintexEditorPropertyMain.SpinContent.Replace(spinkey, spinvalue);
}
沙赫达特

尝试使用正则表达式

        string input = "A man with a {unpleasant woman |disagreeable woman}";
        string output =  Regex.Replace(input, @"\bman\b", "abc");
        Console.WriteLine(output);

\ b表示单词边界。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章