Home All Groups Group Topic Archive Search About

How Do I Kill Non-Printable Characters?

Author
2 Dec 2006 1:07 PM
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

*** Sent via Developersdex http://www.developersdex.com ***

Author
2 Dec 2006 1:24 PM
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


Show quoteHide quote
"William Foster" <nospam@devdex.com> schreef in bericht
news:ONBHgLhFHHA.3668@TK2MSFTNGP02.phx.gbl...
> 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
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
2 Dec 2006 11:08 PM
William Foster
Cor,

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

Yours sincerely,

William Foster

*** Sent via Developersdex http://www.developersdex.com ***