/// <summary> /// 搜索高亮 /// </summary> /// <param name="inputText">inputText</param> /// <param name="searchWord">搜索的关键字</param> protected string HighlightText(string inputText, string searchWord) { System.Text.RegularExpressions.Regex expression = new System.Text.RegularExpressions.Regex(searchWord.Replace(" ", "|"), System.Text.RegularExpressions.RegexOptions.IgnoreCase); return expression.Replace(inputText, new System.Text.RegularExpressions.MatchEvaluator(ReplaceKeywords)); } /// <summary> /// 替换方法 /// </summary> /// <param name="m"></param> /// <returns></returns> public string ReplaceKeywords(System.Text.RegularExpressions.Match m) { return "<span class='highlightTxtSearch'>" + m.Value + "</span>"; }