How to remove all whitespace characters from a String?
Try using Linq in order to filter out white spaces:
using System.Linq;
...
string source = "abc \t def\r\n789";
string result = string.Concat(source.Where(c => !char.IsWhiteSpace(c)));
Console.WriteLine(result);
Outcome:
abcdef789
One way is to use Regex
public static string ReplaceAllWhiteSpaces(string str) {
return Regex.Replace(str, @"\s+", String.Empty);
}
Taken from: https://codereview.stackexchange.com/questions/64935/replace-each-whitespace-in-a-string-with-20