473,503 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
+ 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 10121
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
2778
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
12213
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
1629
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
2637
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
22381
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
3355
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
5342
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
8448
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
4151
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
7205
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
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
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 ...
0
401
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.