我需要突出显示用户在我的 gridview 中搜索的所有单词
我试试这个
public string Highlight(string InputTxt)
{
string Outputtext = "";
Regex RegExp ;
string[] separators = { ",", ".", "!", "?", ";", ":", " " };
string[] words = InputTxt.Split(separators, StringSplitOptions.RemoveEmptyEntries);
string strSearch = TextBox1.Text;
string[] Strseacharr = strSearch.Split(separators, StringSplitOptions.RemoveEmptyEntries);
foreach (var word in words)
{
foreach(var wordtosearch in Strseacharr)
{
if (VSM.stem(word) == VSM.stem(wordtosearch))
{
RegExp =new Regex(word.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);
return Outputtext+=RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));
}
}
}
Label2.Text = Outputtext;
return Outputtext+="";
}
public string ReplaceKeyWords(Match m)
{
if (VSM.stem(m.Value.ToString()) == VSM.stem(TextBox1.Text))
return "<span class=highlight>" +m.Value+ "</span>";
else
return m.Value;
}
在我的 gridview 字段中,我正在使用它
<asp:Label ID="Label6" runat="server"
Text='<%# Highlight(Eval("DocumentSummary").ToString()) %>'>
</asp:Label>