Friday, 15 July 2011

.net - Is there a way in C# to replace a collection of characters with another collection respectively? -



.net - Is there a way in C# to replace a collection of characters with another collection respectively? -

is there way in c# replace collection of characters collection respectively following:

"abcdef.kindofreplace( "ae", "12"); // result: "1bcd2f"

no there isn't seems me code equivalent to:

var mystring = "abcdef"; var newstring = mystring.replace("a", "1").replace("e", "2");

you write extension method create nicer, big replacement arrays wouldn't particularly efficient.

edit:

as pointed out in comments below utilize stringbuilder in cases have big number of strings/chars replace.

.net regex string replace

No comments:

Post a Comment