Problem w/ special characters in a filestream

G

Guest

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
 
A

Armin Zingler

Engineerik said:
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
 
G

Guest

:
....
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
 

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