Replace Method case insensitive
-
This is what I do with ASP3.0. If a user enters "This is green color" I want to first search if the word "green" color exists then replace the word "green" with <font color=green>green</font>. When searching for the word I don't need it to be case sensitive and when replacing the word I want to preserve the case. For exmple, if user enters "This is GrEEn color" I want to replace the word GrEEn with <font color=GrEEn>GrEEn</font>. This is pretty easy with VB's case insensitive instr and replace but I can't seem to find a simple solution in C#
-
This is what I do with ASP3.0. If a user enters "This is green color" I want to first search if the word "green" color exists then replace the word "green" with <font color=green>green</font>. When searching for the word I don't need it to be case sensitive and when replacing the word I want to preserve the case. For exmple, if user enters "This is GrEEn color" I want to replace the word GrEEn with <font color=GrEEn>GrEEn</font>. This is pretty easy with VB's case insensitive instr and replace but I can't seem to find a simple solution in C#
awu25 wrote: if user enters "This is GrEEn color" I want to replace the word GrEEn with GrEEn. try regular expressions
Dim r As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex("red", System.Text.RegularExpressions.RegexOptions.IgnoreCase) Dim s As String = "word1 word2 reD word3" Dim s2 As String = r.Match(s).Value Dim res As String = r.Replace(s, "[font color=" & s2 & "]" & s2 & "[/font]")