473,473 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Bug in StreamReader.ReadLine()? It reads special chars wrong...

VMI
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.
Nov 16 '05 #1
3 10115
VMI
Never mind.

I tried :
new StreamReader(filename, Encoding.Default);
and it worked fine with one of the special chars. I hope it works with all
of the strange chars.

Thanks anyway.

"VMI" <vo******@yahoo.com> wrote in message
news:el**************@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.

Nov 16 '05 #2

"VMI" <vo******@yahoo.com> wrote in message
news:el**************@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.Defaul t);

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
Nov 16 '05 #3
VMI wrote:
Never mind.

I tried :
new StreamReader(filename, Encoding.Default);
and it worked fine with one of the special chars. I hope it works
with all of the strange chars.


Depends on what "all" are. In the end, Encoding.Default is just your
Windows' default (8 bit) code page. If you only deal with text files created
in that particular environment, you're safe. Otherwise you're better off
using Unicode.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jonas Meurer | last post by:
hello, my script selects a comment saved as VARCHAR in MySQL and displays it inside an html page. the problem is, that the comment contains several special characters, as mysterious utf-8...
5
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split()...
2
by: Thorsten Viel | last post by:
Hi List, im trying to use special chars with the std::string (like S) but when i cout<< the string the special chars have disappeared. What's wrong here? Thanks in advance
4
by: dutch disCo | last post by:
Hi, I'm trying to use GET method to pass variables through my script files. Unfortunately, when a special char (&, ?, +) is being posted the variable gets trimmed in a very strange way. I'm...
7
by: Eric | last post by:
I am trying to save the "last read" position of a file using a StreamReader object. I am reading the lines of the file using StreamReader.ReadLine and then saving the current position in the...
1
by: Henry | last post by:
Hi, reading a textfile with the ReadLine method of a Streamreader objects the resulting string does not contain the special characters from the source file: e.g. Paragraph § and all the umlauts...
2
by: Kin | last post by:
I am trying to read the output of an external application using redirected stdout and StreamReader::ReadLine(). The problem is that ReadLine() blocks and I am either reading nothing or just part...
2
by: Eddy | last post by:
I have a big problem with streamreader ReadLine()! I read from a long text files about 13k lines, than I encounter a problem: ReadLine() is not anymore able to go on! I have a string whose name is...
5
by: Alex | last post by:
Hi all - Is there a standard way to handle special chars in strings in dotnet? I'm using csharp and having two seperate problems... 1. Passing in args... I need to pass in an arg that...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.