vendredi 9 octobre 2015

How can I convert values stored in ANSI (Windows 1252) in a database to UTF-8

When I open a legacy database in Sqlite Browser, the text is already displayed wrong. The only encoding I can set is UTF-8 and UTF-16.
Sqlite browser with Umlaut

When I query the database, the encoding is already wrong in Visual Studio.
Visual Studio locals

I assume the text is encoded in ANSI (Windows-1252). I tried converting it to UTF-8

        var encoding = Encoding.GetEncoding(1252);
        byte[] encBytes = encoding.GetBytes(result);
        byte[] utf8Bytes = Encoding.Convert(encoding, Encoding.UTF8, encBytes);
        return Encoding.UTF8.GetString(utf8Bytes);

but now the question mark symbol is just a question mark.
Still wrong

Somehow, the external legacy app displays it correctly, so there appears to be a way. But I'm not sure what I can try next.

Aucun commentaire:

Enregistrer un commentaire