string .replace function question (maintain caps)

  • Thread starter Thread starter Cirene
  • Start date Start date
C

Cirene

How do I replace in a non-casesensitive way, but maintain the capitilization
of this example....

mystring = "Hello WORLD! I want this to work!"
mystring = mystring.Replace("world", "earth")

What I want is this to be the outcome: "Hello earth! I want this to work!"

I want "WORLD" to be replaced, regardless of the capitalization. I also
want the capitalization to be maintained.

Thanks.
 
Cirene,

mystring = "Hello WORLD! I want this to work!";
mystring = System.Text.RegularExpressions.Regex.Replace(
mystring, "world", "earth",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);

HTH
 
Back
Top