473,403 Members | 2,354 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,403 software developers and data experts.

Problem with accents i.e. é when reading a text file

Hi I have a trivial question for the experts.

I would lilke to read be able to read a text file that could contain french
characters with accents.
I'm opening the file with the File.openText(...) and
then loop through the file with the Readline function into a string variable.
But everytime a hit a char with an accent I loses it.

Example : père reads pre

Thanks in advance

Chérif

Jul 21 '05 #1
3 8666
Cherif Diallo <Ch**********@discussions.microsoft.com> wrote:
Hi I have a trivial question for the experts.

I would lilke to read be able to read a text file that could contain french
characters with accents.
I'm opening the file with the File.openText(...) and
then loop through the file with the Readline function into a string variable.
But everytime a hit a char with an accent I loses it.


You need to specify the correct encoding. File.OpenText reads the text
using a UTF-8 encoding, which is probably not what you want. Use
StreamReader to open the file and read the text using the correct
encoding. What is the encoding of your file?

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information about encodings.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
If you know that your system is set up with a code page capable of showing
French accented letters, you can use System.Text.Encoding.Default with
StreamReader (as Jon suggested) which will give you the encoding for this
code page. This will work even if your files are not saved in one of the
unicode formats.

Regards, Jakob.
"Jon Skeet [C# MVP]" wrote:
Cherif Diallo <Ch**********@discussions.microsoft.com> wrote:
Hi I have a trivial question for the experts.

I would lilke to read be able to read a text file that could contain french
characters with accents.
I'm opening the file with the File.openText(...) and
then loop through the file with the Readline function into a string variable.
But everytime a hit a char with an accent I loses it.


You need to specify the correct encoding. File.OpenText reads the text
using a UTF-8 encoding, which is probably not what you want. Use
StreamReader to open the file and read the text using the correct
encoding. What is the encoding of your file?

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information about encodings.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
Thanks a lot Guys.

It works like a charm.

"Jakob Christensen" wrote:
If you know that your system is set up with a code page capable of showing
French accented letters, you can use System.Text.Encoding.Default with
StreamReader (as Jon suggested) which will give you the encoding for this
code page. This will work even if your files are not saved in one of the
unicode formats.

Regards, Jakob.
"Jon Skeet [C# MVP]" wrote:
Cherif Diallo <Ch**********@discussions.microsoft.com> wrote:
Hi I have a trivial question for the experts.

I would lilke to read be able to read a text file that could contain french
characters with accents.
I'm opening the file with the File.openText(...) and
then loop through the file with the Readline function into a string variable.
But everytime a hit a char with an accent I loses it.


You need to specify the correct encoding. File.OpenText reads the text
using a UTF-8 encoding, which is probably not what you want. Use
StreamReader to open the file and read the text using the correct
encoding. What is the encoding of your file?

See http://www.pobox.com/~skeet/csharp/unicode.html for more
information about encodings.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #4

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: 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...
0
by: blabla120 | last post by:
Hi NG, I want to read a xml-file from an asp-page: // Kategorien aus xml laden string pathKategorien = Server.MapPath("./conf/kategorien.xml"); FileStream fs = new FileStream(pathKategorien,...
3
by: vaibhavkansara | last post by:
Hello friends, I am vaibhav I am a new to PHP/MYSQL.I have a problem to uploading a text file into MYSQL using php, and a text file is a tabdelimited file so pleas give me solution as soon 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.