string .replace function question (maintain caps)

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.
 
M

Milosz Skalecki [MCAD]

Cirene,

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

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top