You could use Linq's Aggregate function:
string s = "the
quick brown
dog,jumped;over the lazy fox.";
char[] chars = new char[] { ' ', ';', ',', '
', ' ', '
' };
string snew = chars.Aggregate(s, (c1, c2) => c1.Replace(c2, '
'));
Here's the extension method:
public static string ReplaceAll(this string seed, char[] chars, char replacementCharacter)
{
return chars.Aggregate(seed, (str, cItem) => str.Replace(cItem, replacementCharacter));
}
Extension method usage example:
string snew = s.ReplaceAll(chars, '
');
string name="$1,300";
Console.Write((name.Replace("$","").Replace(",",""))); // output-> 1300
public static class ExtensionMethods
{
public static string Replace(this string s, char[] separators, string newVal)
{
string[] temp;
temp = s.Split(separators, StringSplitOptions.RemoveEmptyEntries);
return String.Join( newVal, temp );
}
}
// use
char[] separators = new char[]{' ',';',',','
',' ','
'};
string s = "this;is,
a
test";
s = s.Replace(separators, "
");
s/[;,
]|[
]{2}/
/g