Re: Bug in StreamReader.ReadLine()? It reads special chars wrong...
From: David Browne (meat_at_hotmail.com)
Date: 08/02/04
- Next message: Ben Lucas: "Re: Reading from HashTable"
- Previous message: VMI: "Re: Bug in StreamReader.ReadLine()? It reads special chars wrong..."
- In reply to: VMI: "Bug in StreamReader.ReadLine()? It reads special chars wrong..."
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 2 Aug 2004 17:28:38 -0500
"VMI" <vonchi_m@yahoo.com> wrote in message
news:elBI0nNeEHA.1764@TK2MSFTNGP10.phx.gbl...
> When I execute a ReadLine from an ascii file with special chars (ie. the
> 'Ñ' in "NUÑEZ PEREZ"), it automatically deletes this character. So "NUÑEZ
> PEREZ" becomes "NUEZ PEREZ". How can this be avoided? The reason being
that
> I compare this string to a string in an Access DB (btw, Access also screws
> up with the character by replacing "Ñ" with "-"). So when I compare these
> two strings, they won't match because both systems storing the data
> interpret the char in different ways. The same thing happens with chars
with
> accents (ie. 'ó').
>
> Thanks.
>
>
ASCII is a 7-bit encoding and has no 'Ñ'. In order to have that character,
your file must use an encoding other than ASCII. You must discover what
that encoding is and tell the StreamReader. By default it uses
UTF8Encoding.
Try
StreamReader sr = new
StreamReader("foo.txt",System.Text.Encoding.Default);
That will us your computer's regional settings to get the current code page,
or figure out what code page is used for your file and specify it.
David
- Next message: Ben Lucas: "Re: Reading from HashTable"
- Previous message: VMI: "Re: Bug in StreamReader.ReadLine()? It reads special chars wrong..."
- In reply to: VMI: "Bug in StreamReader.ReadLine()? It reads special chars wrong..."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|