atmosphere1212 Posted November 29, 2004 Posted November 29, 2004 (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 November 29, 2004 by atmosphere1212 Quote
HJB417 Posted November 30, 2004 Posted November 30, 2004 try using a binary reader. basically, a class that derives from Stream Quote
atmosphere1212 Posted November 30, 2004 Author Posted November 30, 2004 (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 November 30, 2004 by atmosphere1212 Quote
Administrators PlausiblyDamp Posted November 30, 2004 Administrators Posted November 30, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
HJB417 Posted December 1, 2004 Posted December 1, 2004 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. Quote
Administrators PlausiblyDamp Posted December 1, 2004 Administrators Posted December 1, 2004 Different encodings are not just a problem with UTF-16, there are various Double Byte encodings (e.g. Shift_JIS), UTF-8 is a Multi-Byte encoding format as well. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.