473,419 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Reading a text file with spanish accents

I am at an absolute loss on what is going on here. I have a text file
with some Spanish writing. Some of the characters have accents. I have
not found anyway to read this text file and echo the output to the
console showing the accents.

I have tried using UTF-8 but it does not like the accent characters.

It basically converts
Añoro esta situación

to
A?oro esta situaci?n

What am I missing?
Amy
Oct 12 '07 #1
5 9638
Amy,

Well, it's possible that you are reading the file correctly from UTF-8,
but the font for the console doesn't support those characters. What is the
font that you are using and does it support those characters?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Amy L." <am**@paxemail.comwrote in message
news:eJ**************@TK2MSFTNGP05.phx.gbl...
>I am at an absolute loss on what is going on here. I have a text file with
some Spanish writing. Some of the characters have accents. I have not
found anyway to read this text file and echo the output to the console
showing the accents.

I have tried using UTF-8 but it does not like the accent characters.

It basically converts
Añoro esta situación

to
A?oro esta situaci?n

What am I missing?
Amy
Oct 12 '07 #2
Amy,

The Spanish characters are in the 1252 characterset. It is in my idea good
to check that in the Country settings . The way to handle this seems for me
in almost every Windows OS version different, so I cannot tell you that. I
have had problems enough with this where in not every application the
characters were showed right although that was when using combined set 1250
and 1252.

http://msdn2.microsoft.com/en-us/library/aa912040.aspx

Cor

Oct 12 '07 #3
Nicholas Paldino [.NET/C# MVP] wrote:
Amy,

Well, it's possible that you are reading the file correctly from
UTF-8, but the font for the console doesn't support those characters.
What is the font that you are using and does it support those characters?

In testing I decided to print each char to the screen along with its
byte value. The code is merely a (int)c where c is a char.

When using StreamReader with Encoding.UTF8 the ñ gets displayed as a ?
with a code of 65535

When using StreamReader with Encoding.Default the ñ gets displayed as a
ñ with a code of 241

When using FileStream with no encoding (don't believe you can set it)
and than printing the characters of the bytes ñ gets displayed as a ñ
with a code of 241.

When attempting to convert the byte array returned from the FileStream
to a String in UTF8 via below the sting does not convert properly (I get
the ? for the accented characters).

UTF8Encoding temp = new UTF8Encoding( true );
Console.WriteLine( temp.GetString( b ) );

However, if I do
Console.WriteLine( System.Text.Encoding.Default.GetString( b ) );

It prints correctly.

I have read that using "Encoding.Default" is not good - however it seems
to be the only thing that works. I know the characters are for the most
part being read in correctly especially with FileStream. It just seems
like I am lost on what to do about the encoding of them.

Thoughts?
Darrell

Oct 12 '07 #4
Amy L. <am**@paxemail.comwrote:

<snip>
However, if I do
Console.WriteLine( System.Text.Encoding.Default.GetString( b ) );

It prints correctly.

I have read that using "Encoding.Default" is not good - however it seems
to be the only thing that works. I know the characters are for the most
part being read in correctly especially with FileStream. It just seems
like I am lost on what to do about the encoding of them.
*Characters* are not read at all by a FileStream. Bytes are read by a
FileStream. An Encoding is the way of converting between bytes and
characters.

If your file is effectively encoded using Encoding.Default, that's what
you should use. It would be generally better if you were able to start
with a UTF-8 file, but if you can't control whatever produces the file,
then you need to follow its lead.

Picking an encoding is a bit like picking an image format - you might
prefer PNG to BMP, but if someone gives you a BMP file and you try to
read it as if it were a PNG, you won't get the right picture.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 12 '07 #5
Hi Amy,

Just a quick bit of info of the top of my head, (i havent read into
detail about your problem in the above discussion), but what first
comes to mind is why you are trying to use UTF-8 and NOT UTF-16.

The 8 stands for 8bits which is can hold 0-255 decimal values (ala
ASCII character set). UTF-16 was introduced to handle international
character-sets, as it is 16bit, hence a capacity to hold 65536
different characters - from 0 - 65535 (64k)

Hope this helps.

Cheers,
Ben

Oct 12 '07 #6

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

Similar topics

1
by: fabrice | last post by:
Hello, I've got trouble reading a text file (event viewer dump) by using the getline() function... After 200 - 300 lines that are read correctly, it suddenly stops reading the rest of the...
14
by: Job Lot | last post by:
I have tab delimited text file which gets populated on daily basis via automated process. New entry is written at the bottom. I need to create a utility which makes a copy of this file with 10 most...
8
by: Phil Slater | last post by:
I'm trying to process a collection of text files, reading word by word. The program run hangs whenever it encounters a word with an accented letter (like rôle or passé) - ie something that's not a...
7
by: Drew Berkemeyer | last post by:
Hello, I'm using the following code to read a text file in VB.NET. Dim sr As StreamReader = File.OpenText(strFilePath) Dim input As String = sr.ReadLine() While Not input Is Nothing...
4
by: Nina | last post by:
Hi everyone, Do you know why the following code only read certain number of lines of text file, but not the entire file? Dim sr As StreamReader Dim str As String Dim al As ArrayList = New...
4
by: Amit Maheshwari | last post by:
I need to read text file having data either comma seperated or tab seperated or any custom seperator and convert into a DataSet in C# . I tried Microsoft Text Driver and Microsoft.Jet.OLEDB.4.0...
1
by: John | last post by:
I have a process that reads a text file then uploads the data into a database table. The text file has 10 lines at the end of the file that are blank BUT it appears that the enter key or space bar...
3
by: John | last post by:
How can I tell if a line begins with a number instead of a character? I need to read a text file and some of the data begins with a character which is causing me an issue in reading and uploading...
1
by: JM | last post by:
Hi, I have been trying to read a file, using "StreamReader" to pass the info to an string that is: ....dim stream as new FileStream(file,...) dim sr as new StreamReader(stream) dim data as...
3
by: jasvinder singh | last post by:
Respected Sir/madam, Can you help in providing code in 'C' for Reading text file with n number of rows and columns and putting the result in arrays.The sample file is as follows: rim_label =...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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,...
0
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
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,...
0
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
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...

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.