473,394 Members | 1,778 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,394 software developers and data experts.

Character encoding problem?

Hi,

I am reading a text file using a StreamReader in C# but the reader is unable
to handle some of the characheters.

Using the default encoding the program cannot handle accented characters. I
tried opening the file using other encodings e.g. UTF7.
UTF7 fixed the accents but cannot hadle the plus sign x2B. I am also having
problems with the Euro symbol x80 and quote x92.

How do I read this file correctly?
Is this problem caused by the encoding?
Is there a way to determine the file's encoding at runtime?
How else can I find out the encoding?

Thanks

Colin

Jul 21 '05 #1
2 7557
CMan <cm**@nospam.nospam> wrote:
I am reading a text file using a StreamReader in C# but the reader is unable
to handle some of the characheters.

Using the default encoding the program cannot handle accented characters. I
tried opening the file using other encodings e.g. UTF7.
UTF7 fixed the accents but cannot hadle the plus sign x2B. I am also having
problems with the Euro symbol x80 and quote x92.
If your file is using 0x80 for the Euro symbol, that should help to
narrow it down...

Have you tried using Encoding.Default? That's not the same as the
default encoding for StreamReader when you don't specify an encoding.
(It's the default encoding for your computer, instead.)
How do I read this file correctly?
By specifying the correct encoding.
Is this problem caused by the encoding?
Almost certainly.
Is there a way to determine the file's encoding at runtime?
There are ways you can try to guess it heuristically, but nothing
foolproof.
How else can I find out the encoding?


Well, what generated this text file to start with?

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

--
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
Thanks Jon.

You got in one. Encoding.Default fixed on my my machine.

Should have spotted that one.

Colin
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
CMan <cm**@nospam.nospam> wrote:
I am reading a text file using a StreamReader in C# but the reader is unable to handle some of the characheters.

Using the default encoding the program cannot handle accented characters. I tried opening the file using other encodings e.g. UTF7.
UTF7 fixed the accents but cannot hadle the plus sign x2B. I am also having problems with the Euro symbol x80 and quote x92.


If your file is using 0x80 for the Euro symbol, that should help to
narrow it down...

Have you tried using Encoding.Default? That's not the same as the
default encoding for StreamReader when you don't specify an encoding.
(It's the default encoding for your computer, instead.)
How do I read this file correctly?


By specifying the correct encoding.
Is this problem caused by the encoding?


Almost certainly.
Is there a way to determine the file's encoding at runtime?


There are ways you can try to guess it heuristically, but nothing
foolproof.
How else can I find out the encoding?


Well, what generated this text file to start with?

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

--
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

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

Similar topics

9
by: Safalra | last post by:
The idea here is relatively simple: a java program (I'm using JDK1.4 if that makes a difference) that loads an HTML file, removes invalid characters (or replaces them in the case of common ones...
4
by: HeroOfSpielburg | last post by:
Hello, I am trying to using the Shift_JIS character set in my web pages, and have specified it as such in the <head>. <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> ...
8
by: Agnes | last post by:
In my .net ,i need to generate an xml file , however, user may input a chinese character, Then , the xml will got something unknow characters. the following is my code, Does anyone know how to...
6
by: Pavils Jurjans | last post by:
Hello, I am experiencing a weird behaviour on my ASP.NET project. The project consists from client-side, which can be whatever environment - web page, EXE application, etc. The client sends HTTP...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
18
by: Marcel Saucier | last post by:
Hello, I want to use the above characters codes chart but I dont know how to set the typeface (documentation: The characters that appear in Windows above 127 depend on the selected typeface). ...
17
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
1
by: PHP Wooer | last post by:
Can anybody there please help me out? I am having a problem with the display of Japanese character in the subject line of the mails sent in Japanese language. This problem is particularly with...
14
by: Ioannis Vranos | last post by:
The following code does not work as expected: #include <wchar.h> #include <locale.h> #include <stdio.h> #include <stddef.h> int main() {
10
by: Paul W | last post by:
Hi all, I have an application that reads data in from a text file and stores it in a database. My problem is that there are some characters in the file that aren't being handled properly. For...
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
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?
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
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
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
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
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.