decoding ISO 8859

L

Lonewolf

Hi all,
I'm trying to decode a byte array containing char conforming to ISO
8859 standard, it is a german text actually. I tried using the old win32
MultiByteToWide API, using CP_ACP as the code page with the locale set
to german. It works most of the time, but certain strings will display
funny char. It is perhaps due to the API's limitation in conversion. I
looked through the System.Text.Decoder class but it seems there is no
way for me to specify ISO-8859 format as the decoder. Can someone
enlighten me on this?
 
J

Joerg Jooss

Thus wrote Lonewolf,
Hi all,
I'm trying to decode a byte array containing char conforming to ISO
8859 standard, it is a german text actually. I tried using the old
win32
MultiByteToWide API, using CP_ACP as the code page with the locale set
to german. It works most of the time, but certain strings will display
funny char.
It is perhaps due to the API's limitation in conversion. I
looked through the System.Text.Decoder class but it seems there is no
way for me to specify ISO-8859 format as the decoder. Can someone
enlighten me on this?

System.Text.Encoding is the BCL class to encode and decode character strings
(Encoder and Decoder are collaborating objects).

There are quite a few encodings in the ISO-8859-x family. I'm assuming you're
referring to ISO-8859-1.

// Create an Encoding by Win32 code page identifier
Encoding latin1 = Encoding.GetEncoding(28591);

// Create an Encoding by IANA name
Encoding latin1 = Encoding.GetEncoding("iso-8859-1");

// Decode byte sequence
byte[] bytes = ReadLatin1EncodedContent();
string text = latin1.GetString(bytes);

A list of all Win32 code page identifiers can be found in the Platform SDK:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_81rn.asp

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top