Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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