using System.Text.RegularExpressions;
public static void Main()
for (int i = 0; i <= 31; i++) {
text += " " + i + "_" + (char) i;
text += " " + 127 + "_" + (char) 127;
Console.WriteLine("Original text: '" + text + "'");
var newtext = Regex.Replace(text, "[\x0-\x1F]", "");
Console.WriteLine("New text: '" + newtext + "'");