gpt4 book ai didi

c# - 如何替换字符串中的单词

转载 作者:行者123 更新时间:2023-11-30 19:06:17 25 4
gpt4 key购买 nike

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

我试过这个:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com