Home All Groups Group Topic Archive Search About

Problem w/ special characters in a filestream

Author
17 Mar 2006 6:36 PM
Engineerik
using vb.net 2003, I am reading an ascii text file which is shared with a
legacy DOS program.  The characters "«" (ascii code 171) and "¬" (ascii code
172) are used in the file.  The DOS app reads these as binary input and  when
converted to text they translate to characters "½" (ascii code 189) and "¼"
(ascii code 188) respectively.
When using a StreamReader to read the file the characters do not appear at
all.  That is the line in the file when viewed with notpad or any other
simple text editor may include the line "no more than ¬ inch deep" but when
this line is read using the readline method of the streamreader the string
returned is "no more than  inch deep"

How can I find these characters in the filestream and replace them with the
"½" and  "¼" characters?

Erik

Author
17 Mar 2006 7:20 PM
Armin Zingler
Show quote Hide quote
"Engineerik" <Enginee***@discussions.microsoft.com> schrieb
> using vb.net 2003, I am reading an ascii text file which is shared
> with a legacy DOS program.  The characters "«" (ascii code 171) and
> "¬" (ascii code 172) are used in the file.  The DOS app reads these
> as binary input and  when converted to text they translate to
> characters "½" (ascii code 189) and "¼" (ascii code 188)
> respectively.
> When using a StreamReader to read the file the characters do not
> appear at all.  That is the line in the file when viewed with notpad
> or any other simple text editor may include the line "no more than ¬
> inch deep" but when this line is read using the readline method of
> the streamreader the string returned is "no more than  inch deep"
>
> How can I find these characters in the filestream and replace them
> with the "½" and  "¼" characters?


It seems the DOS application reads a DOS encoded file (probably codepage 437
"OEM USA") and writes an ANSI encoded file. I think so because the char code
of "½" on code page 437 is 171.

Try passing System.Text.Encoding.Default to the streamreader when reading
the file.

Be aware that ASCII (System.Text.Encoding.ASCII) is 7 Bits only (char codes
0-127).



Armin
Author
17 Mar 2006 8:00 PM
Engineerik
"Armin Zingler" wrote:
....
>
> Try passing System.Text.Encoding.Default to the streamreader when reading
> the file.
>
....>
> Armin
>
>


(Lights coming on)
I knew there had to be something simple and I have not really had to deal
with Encoding stuff much.

Thanks for the help.
Erik