Search code examples
delphiencodingcodepages

How to restore text broken due to wrong encoding in Delphi?


I use Delphi 2009. I receive a text as String that looks like 'Визгунов (ранний) {VHS}'. Using online decoders, I was able to determine that it's actually Win-1251 codepage.

What should I do to restore it back to normal, in other words to make it readable again?


Solution

  • var s: string;
        rbs: RawByteString;
    begin
        rbs := Utf8ToAnsi('Визгунов (ранний) {VHS}');
        SetCodePage(rbs, 1251, false);
        s := string(rbs); // s = 'Визгунов (ранний) {VHS}'
    end;