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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top