5,699,997 members and growing! (14,905 online)
Email Password   helpLost your password?
Languages » C# » General     Beginner License: The Code Project Open License (CPOL)

Encoding Accented Characters

By Simon Hughes

There is a problem exporting accented characters in plain text files. You need to encode, but which one?
C# 3.0, C# 1.0, C# 2.0, C#, Windows, .NET, .NET 3.0, .NET 1.0, .NET 1.1, .NET 2.0VS.NET2002, VS.NET2003, VS2005, Visual Studio, Dev

Posted: 22 May 2007
Updated: 22 May 2007
Views: 7,500
Bookmarked: 11 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.10 Rating: 3.44 out of 5
2 votes, 25.0%
1
1 vote, 12.5%
2
0 votes, 0.0%
3
1 vote, 12.5%
4
4 votes, 50.0%
5

Introduction

There is a problem exporting accented characters in text files. Some programs cannot import or correctly display accented characters. Therefore you need to use encoding to correctly export a plain text file. However, there are a LOT of encodings, so which one should you use?

Here's How

The answer is: iso-8859-8.

That is the Hebrew (ISO-Visual) encoding. The encoding is natively supported in .NET. It intelligently converts to a visual format for you. The other standard encoders do not do this as you will see below.

Example

Converting the following: Frédéric François.

Encoding Description Output
ASCII Fr?d?ric Fran?ois
Default Frédéric François
UTF7 Unicode (UTF-7) Fr+AOk-d+AOk-ric Fran+AOc-ois
UTF8 Unicode (UTF-8) Frédéric François
iso-8859-1 Western European (ISO) Frédéric François
iso-8859-8 Hebrew (ISO-Visual) Frederic Francois
us-ascii US-ASCII Fr?d?ric Fran?ois
Windows-1252 Western European (Windows) Frédéric François

Example of Code Using Encoding

StreamWriter sw = new StreamWriter
    ("somefile.txt", false, System.Text.Encoding.GetEncoding("iso-8859-8"));

A Full Example for the Beginner

using (StreamWriter sw = new StreamWriter
    ("somefile.txt", false, System.Text.Encoding.GetEncoding("iso-8859-8")))
{
    DataSet1TableAdapters.binsTA ta = new DataSet1TableAdapters.binsTA();
    DataSet1.binsDataTable dt = ta.GetData();
    foreach (DataSet1.binsRow row in dt.Rows)
    {
        sw.Write(row.ID.ToString());
        sw.Write("|");
        sw.WriteLine(row.description);
    }
}

History

  • 22nd May, 2007: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Simon Hughes


C++ Developer for 18 years. Microsoft Certified.
Occupation: Software Developer (Senior)
Location: United Kingdom United Kingdom

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralDoesn't work for me [modified]memberDEGT4:15 27 Aug '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 22 May 2007
Editor: Deeksha Shenoy
Copyright 2007 by Simon Hughes
Everything else Copyright © CodeProject, 1999-2008
Web08 | Advertise on the Code Project