473,395 Members | 1,464 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,395 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 8661
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
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
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...

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.