C# string "search and replace" using a regex

Posted by rsturim on Stack Overflow See other posts from Stack Overflow or by rsturim
Published on 2010-03-26T19:42:27Z Indexed on 2010/03/26 19:43 UTC
Read the original article Hit count: 607

Filed under:
|

I need to do a 2 rule "replace" -- my rules are, replace all open parens, "(" with a hyphen "-" and strip out all closing parens ")".

So for example this:

"foobar(baz2)" would become

"foobar-baz2"

I currently do it like this -- but, my hunch regex would be cleaner.

myString.Replace("(", "-").Replace(")", "");

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex