473,792 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8759
Cherif Diallo <Ch**********@d iscussions.micr osoft.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.co m>
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.Enc oding.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**********@d iscussions.micr osoft.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.co m>
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.Enc oding.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**********@d iscussions.micr osoft.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.co m>
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
7056
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 file... Thank you to all of you who can help me with this one...
14
4582
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 recent entries. When I read line using StreamReader object it starts from the top, so looping though lines and keeping track of the line is not helpful. Is there anyway to start reading from the bottom or if anyone could suggest some other...
8
18253
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 "char" with an ASCII code in 0..127 I've searched the ANSI C++ standard, the internet and various text books, but can't see how to workaround this one. I've tried wchar_t and wstring without success. But rather than spending lots of time on...
7
7773
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 strReturn += input + vbCrLf input = sr.Read
4
1542
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 ArrayList Do str = sr.ReadLine
4
12808
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 to read text file but could not get the data in correct format. All columns are not coming in dataset and rows are messing up. Suggestions please ???
1
2230
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 string = sr.ReadToEnd... My problem is that in the file (is a text file) there is some data like:
0
1323
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, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader sr = new StreamReader( fs );
3
1989
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 possible .Thanks in advance. Vaibhav
3
3188
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 = 'aeff5' state 0 = 'eee' state 1 = 'ffffff' . .and so on...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.