c# string replace multiple matches with one charactar
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[]{' ',';',',','\r','\t','\n'};
string s = "this;is,\ra\t\n\n\ntest";
s = s.Replace(separators, "\n");
3.8
2
s/[;,\t\r ]|[\n]{2}/\n/g
Thank you!
2
0
Are there any code examples left?
New code examples in category Other