How Do I Kill Non-Printable Characters?

W

William Foster

Good evening all,

I have an annoying query regarding non-printable characters. I am
undertaking data validation on a very large CSV file retrieved from a
SQL Database, anything on the other side of the file retrieval is
totally out of my control. Unfortunately, there has been some issue in
the database which has meant that in large numbers of ASCII CHAR(0) has
been included in some of the CSV fields. This has resulted in my data
validation collapsing.

I have tried reading each character of the text file to remove the
occurrences of CHAR(0) with no success, I am guessing because when
importing the file through a StreamReader there are too many
occurrences.

My question is whether there is another way to read a file so that I can
recognise and kill all occurrences of CHAR(0). I am guessing if I read
the file as Hexadecimal it would work, but I have been unable to find
the native .NET method to do this; if it exists.

I have tried StreamReader and BinaryReader (I have no idea why I choose
to try this).

I am using VB.NET 2003.

Thanking you in advance!

Yours sincerely,

William Foster
 
C

Cor Ligthert [MVP]

William,

Are you sure that this simple code is not working

\\\
Dim str As String = "I am from here " & Chr(0) _
& "not readable" & Chr(0) & " anymore"
MessageBox.Show(str.ToString)
str = str.Replace(Chr(0), "")
MessageBox.Show(str.ToString)
///

be sure that you set the resultvalue.

Cor
 
W

William Foster

Cor,

Thanks for that, I have no idea why it wasn't working when I did it.

Yours sincerely,

William Foster
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top