Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace everything in string except...

Status
Not open for further replies.

sammye

Programmer
Oct 5, 2007
35
US
Hello,

Does anyone have any tips on replacing every character in a string with "something1" except for "something2"? For example:

Given string "xxAyxx", replace every character which is not an 'x' with a 'g'.

Start: "xxAyxx"
Result: "xxggxx"

Thanks
 
Never mind, found it:

System.Text.RegularExpressions.Regex.Replace("xxAyxx", "[^x]", "g")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top