[fpc-pascal] converting to UTF8
LacaK
lacak at zoznam.sk
Wed Mar 23 09:51:20 CET 2022
> procedure TestString;
> var
> Original:string;
> Converted:string;
> begin
> original:='ESPA'#209'A'; //ESPAÑA WIN1252
> Converted:=ansiToUtf8(original); // converts to 'ESPA'#239#191#189'A'
> // converted Should be 'ESPA'#195#145'A'
> end;
>
> I've tried playing with strings types, string, rawstring,ansistring,
> utf8string. No way. Any hint?
>
To explicityly convert between run-time code pages you can use
procedure: SetCodePage(var s: RawByteString; CodePage: TSystemCodePage;
Convert: Boolean = True)
SetCodePage(original, 1252, False);
SetCodePage(original, CP_UTF8, True);
-Laco.
More information about the fpc-pascal
mailing list