ralphtrent
Programmer
Hello
I am using RegEx to search for text in a string. Since I need the search to be case-insentive this looked to be my only option. My main purpose for the replacement is to highlight the backround of a text (based on a search). This works well, but the text gets replaced with the incorrect case. Here is my code
this is the output
what I need is this
I need to keep the same case as the origional string. The reason it is getting lower cased is because the text is lower cased in my array.
Any ideas on how i can do this?
I am using RegEx to search for text in a string. Since I need the search to be case-insentive this looked to be my only option. My main purpose for the replacement is to highlight the backround of a text (based on a search). This works well, but the text gets replaced with the incorrect case. Here is my code
Code:
string sWorkNotes = "Ralph and Pete work together"
string[] sSearchPhrase = new string[2]{"ralph","pete"};
foreach(string s in sSearchPhrase)
{
sWorkNotes = System.Text.RegularExpressions.Regex.Replace(sWorkNotes, s, "<span style='background-color:yellow;'>" + s + "</span>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
this is the output
Code:
[highlight]ralph[/highlight] and [highlight]pete[/highlight] work together
what I need is this
Code:
[highlight]Ralph[/highlight] and [highlight]Pete[/highlight] work together
I need to keep the same case as the origional string. The reason it is getting lower cased is because the text is lower cased in my array.
Code:
string[] sSearchPhrase = new string[2]{"ralph","pete"};
Any ideas on how i can do this?