【发布时间】:2017-10-04 17:30:58
【问题描述】:
我试图突出显示 gridview 中的多个关键字。我尝试使用 forloop,但它只突出显示数组中的第一项。
protected string HighlightText(string searchWord, string inputText)
{
// string[] strArray = new string[] { "Hello", "Welcome" };
string s = "d,s";
// Split string on spaces.
// ... This will separate all the words.
string[] words = s.Split(',');
for (int i = 0; i < words.Length; i++)
{
//Console.WriteLine(word);
searchWord = words[i];
Regex expression = new Regex(searchWord.Replace(" ", "|"), RegexOptions.IgnoreCase);
return expression.Replace(inputText, new MatchEvaluator(ReplaceKeywords));
}
return string.Empty;
}
提前谢谢。
这是我只得到关键字“d”被突出显示的输出我还需要突出显示关键字“s”......
【问题讨论】:
-
return在循环内部在第一次迭代中终止其执行。