Skip to content

Instantly share code, notes, and snippets.

@juanonsoftware
Created October 1, 2020 11:00
Show Gist options
  • Save juanonsoftware/413dd04e248cf326faf8c18b9f7e4f83 to your computer and use it in GitHub Desktop.
Save juanonsoftware/413dd04e248cf326faf8c18b9f7e4f83 to your computer and use it in GitHub Desktop.
Remove useless characters from a text stream (read from a text file / html file....)
// Remove multi spaces
const string reduceSpaces = @"[ ]{2,}";
var finalText = Regex.Replace(allText.Replace('\t', ' '), reduceSpaces, " ");
// Remove empty lines
const string emptyLine = @"^\s+$[\r\n]*";
var finalText = Regex.Replace(finalText, emptyLine, string.Empty, RegexOptions.Multiline);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment