gpt4 book ai didi

c# - 正则表达式不是有效的类型或命名空间 C#

转载 作者:太空狗 更新时间:2023-10-29 22:08:29 24 4
gpt4 key购买 nike

我正在尝试将此片段添加到我的代码中:

public string Highlight(string InputTxt)
{
string Search_Str = txtSearch.Text.ToString();

// Setup the regular expression and add the Or operator.
Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);

// Highlight keywords by calling the
//delegate each time a keyword is found.
return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));

// Set the RegExp to null.
RegExp = null;
}

但是,由于某种原因,“Regex”没有出现——找不到类型或命名空间。我想我一定是在使用较新版本的 C# - 任何人都可以帮助我用更新的方法来做到这一点吗?我正在使用 System.Text.RegularExpressions.Regex - 也许他们完全摆脱了它?

最佳答案

using System.Text.RegularExpressions;

尝试那个命名空间。

关于c# - 正则表达式不是有效的类型或命名空间 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7431739/

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