Mar 29, 2019 12:57 PM|RageRiot|LINK
I am creating a search results page and I generate the output in the code behind as a string.
If the user searches for "fox", I'd like to replace the word fox with "<span class='highlight'>fox</div>".
So "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"
becomes "THE QUICK BROWN <span class='highlight'>fox</div> JUMPS OVER THE LAZY DOG".
This is easily done using:
output = Regex.Replace(output, query, "<span class='highlight'>" + query + "</span>" , RegexOptions.IgnoreCase);
However, I'd like to ensure I keep the case of the original string when I replace it - how would I do this?