Non Printable Characters using C#

  • Thread starter Thread starter Greyhound
  • Start date Start date
G

Greyhound

I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.

Many Thanks...
 
Greyhound said:
I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.
Use a FileStream to read the existing file and a FileStream for creating the
new file. .Read() from one and .Write() to the other, skipping the unwanted
characters. A BufferedStream may improve performance.

Anything more and I'd be writing the code for you, and that would be bad.
 
I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.

Just read the text, then remove the appropriate characters using
something like string.Replace. The escape code for FF is "\f" and for
LF it's "\n".

Jon
 
Greyhound said:
I need to remove non-printable characters from a text file. I need to do
this in C#. The Hex codes for the characters I need to remove are '0C' and
'0A' which equate to 12 and 10 in decimal. Their codes are 'FF' and 'LF'
from the ASCII talbe. I have searched and searched and cannot come up with a
method for doing this.

s = Regex.Replace(s, "[\f\n]", "");

or maybe:

s = Regex.Replace(s, "[\u0000-\u001F]", "");

Arne
 
Back
Top