/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public string HighlightKeywords(string input, string keywords) { if (input == string.Empty || keywords == string.Empty) { return input; } var keywordChar = keywords.Split(' '); foreach (var keyword in keywordChar) { try { input = Regex.Replace(input, keyword, string.Format("<span class=\"highlight\">{0}</span>", "$0"), RegexOptions.IgnoreCase); } catch (Exception) { // Log the error. } } return input; }