Using .NET how to convert ISO 8859-1 encoded text files that contain Latin-1 accented characters to UTF-8

You need to get the proper Encoding object. ASCII is just as it’s named: ASCII, meaning that it only supports 7-bit ASCII characters. If what you want to do is convert files, then this is likely easier than dealing with the byte arrays directly. using (System.IO.StreamReader reader = new System.IO.StreamReader(fileName, Encoding.GetEncoding(“iso-8859-1”))) { using (System.IO.StreamWriter writer … Read more

How do I write out a text file in C# with a code page other than UTF-8?

using System.IO; using System.Text; using (StreamWriter sw = new StreamWriter(File.Open(myfilename, FileMode.Create), Encoding.WhateverYouWant)) { sw.WriteLine(“my text…”); } An alternate way of getting your encoding: using System.IO; using System.Text; using (var sw = new StreamWriter(File.Open(@”c:\myfile.txt”, FileMode.CreateNew), Encoding.GetEncoding(“iso-8859-1”))) { sw.WriteLine(“my text…”); } Check out the docs for the StreamWriter constructor.

ISO-8859-1 encoding and binary data preservation

“\u00F6” is not a byte array. It’s a string containing a single char. Execute the following test instead: public static void main(String[] args) throws Exception { byte[] b = new byte[] {(byte) 0x00, (byte) 0xf6}; String s = new String(b, “ISO-8859-1”); // decoding byte[] b2 = s.getBytes(“ISO-8859-1”); // encoding System.out.println(“Are the bytes equal : ” … Read more

Jquery ignores encoding ISO-8859-1

Because I had the same problem, I’ll provide a solution that worked for me. Background: Microsoft Excel is too stupid to export a CSV-File in charset UTF-8: $.ajax({ url: ‘…’, contentType: ‘Content-type: text/plain; charset=iso-8859-1’, // This is the imporant part!!! beforeSend: function(jqXHR) { jqXHR.overrideMimeType(‘text/html;charset=iso-8859-1’); } });

Convert text value in SQL Server from UTF8 to ISO 8859-1

I have written a function to repair UTF-8 text that is stored in a varchar field. To check the fixed values you can use it like this: CREATE TABLE #Table1 (Column1 varchar(max)) INSERT #Table1 VALUES (‘Olá. Gostei do jogo. Quando “baixei” até achei que não iria curtir muito’) SELECT *, NewColumn1 = dbo.DecodeUTF8String(Column1) FROM Table1 … Read more

Convert utf8-characters to iso-88591 and back in PHP

Have a look at iconv() or mb_convert_encoding(). Just by the way: why don’t utf8_encode() and utf8_decode() work for you? utf8_decode — Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1 utf8_encode — Encodes an ISO-8859-1 string to UTF-8 So essentially $utf8 = ‘ÄÖÜ’; // file must be UTF-8 encoded $iso88591_1 = utf8_decode($utf8); … Read more