Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

June 15, 2007

C# to Convert iso-8859-1 to utf-8

Here’s a C# example program to convert from iso-8859-1 to utf-8:

           // Convert iso-8859-1 to utf-8.
            // C# strings are Unicode, so we must first get a byte
            // array containing iso-8859-1 bytes.
            System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1");
            System.Text.Encoding utf_8 = System.Text.Encoding.UTF8;
            // This is our Unicode string:
            string s_unicode = "abcéabc";
            // Convert it to iso-8859-1 bytes
            byte[] isoBytes = iso_8859_1.GetBytes(s_unicode);
            // Convert the bytes to utf-8:
            byte[] utf8Bytes = System.Text.Encoding.Convert(iso_8859_1, utf_8, isoBytes);
            // Let's examine both byte arrays as hex strings.
            // We're using Chilkat.Crypt2 for simplicity...
            Chilkat.Crypt2 crypt = new Chilkat.Crypt2();
            textBox1.Text = crypt.Encode(isoBytes, "hex");
            textBox2.Text = crypt.Encode(utf8Bytes, "hex");
            // The result is this:
            // isoBytes = 616263<strong>E9</strong>616263
            // utf8Bytes = 616263<strong>C3A9</strong>616263
            // The é character is 0xE9 in iso-8859-1, but is represented
            // as two bytes (0xC3 0xA9) in utf-8.

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.