我正在尝试将此片段添加到我的代码中:
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/