is there an quick way to find(and remove) all escape sequences from a Stream/String??
You can use System.Char.IsControl() to detect control characters.
To filter control characters from a string:
public string RemoveControlCharacters(string input)
{
return
input.Where(character => !char.IsControl(character))
.Aggregate(new StringBuilder(), (builder, character) => builder.Append(character))
.ToString();
}
To filter control characters from a stream you can do something similar, however you will first need a way to convert a Stream
to an IEnumerable
.
public IEnumerable _ReadCharacters(Stream input)
{
using(var reader = new StreamReader(input))
{
while(!reader.EndOfStream)
{
foreach(var character in reader.ReadLine())
{
yield return character;
}
}
}
}
Then you can use this method to filter control characters:
public string RemoveControlCharacters(Stream input)
{
return
_ReadCharacters(input)
.Where( character => !Char.IsControl(character))
.Aggregate( new StringBuilder(), ( builder, character ) => builder.Append( character ) )
.ToString();
}