Case insensitive replace on a string

June 08, 2011 - 13:01

I'm sure everyone is familiar with the replace function which replaces all occurances of a string with another string, however this can also be done with the same function but ignoring the case of the compare string.

Dim mystring as string = "One Two Three"
mystring = replace(mystring,"two","TWO", 1,,CompareMethod.Text)

The above code replaces the text "Two" in the string with "TWO" even though the string to compare is passed in lowercase.

© 2011