Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hey,

 

Im reading in characters of text, one by one, and I want to replace any odd characters of text (above ascii 128) with spaces.

 

However.. when i use

 

someInt = myStreamReader.Read

 

It seems to completely skip over these odd characters.. How can I read these characters?

Edited by atmosphere1212
Posted (edited)
try using a binary reader. basically' date=' a class that derives from Stream

 

 

This doesnt work either. Heres my code

 

           Dim curChar As Integer = bStream.Read()

           While curChar <> 13 And curChar <> 26 And curChar <> -1
               curLine += Chr(stripErrorChars(curChar))
               curChar = bStream.Read
           End While

 

That was the code which reads a line of text. The following is the stripErrorChars method

 

       Private Function stripErrorChars(ByVal curChar As Integer) As Integer

           If curChar = 0 Then
               Return 32
           ElseIf curChar >= 128 Then
               Return 32
           Else
               Return curChar
           End If

       End Function

Edited by atmosphere1212
  • Administrators
Posted

What kind of encoding does the text file use? If the data is stored using unicode then you cannot assume each byte represents one character in that manner.

 

You may be better of using something like System.Text.ASCIIEncoding to convert the data to an ASCII based output instead.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
This doesnt work either

 

i've never seen a class that derives from system.io.stream that has a read method that takes no parameters.

 

you're probably using the BinaryReader class which is not derived from system.io.stream and if so, maybe that's your mistake.

 

The encoding will matter if it's unicode16 or higher.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...