[fpc-pascal] Weird string behavior
Santiago A.
svaa at ciberpiula.net
Fri Jul 22 09:56:23 CEST 2016
El 22/07/2016 a las 0:32, Bart escribió:
> On 7/21/16, Santiago A. <svaa at ciberpiula.net> wrote:
>
>> I've come across this issue: When I concatenate two strings in UTF8 they
>> are converted to ansi (Win-1252) .
> You have declared all string variables as plain "string", which is the
> same as AnsiString(CP_ACP). So all string variables have the encoding
> of your active codepage.
>
> Declare Utf8StrA and related as Utf8String.
> In DisplayBytes do not use "String" as parametertype, since this will
> again automatically convert things.
> The AnsiToUtf8 is not necessary anymore if done this way:
var
AnsiStrA:string; // AnsiString(CP_ACP)
AnsiStrB:string; // AnsiString(CP_ACP)
Utf8StrA: string; // AnsiString(CP_ACP)
Utf8StrB: string; // AnsiString(CP_ACP)
Utf8StrConcat:string; // AnsiString(CP_ACP)
begin
AnsiStrA:=' ';
AnsiStrA[1]:=#243; // o acute win-1252
AnsiStrB:='A';
// AnsiStrA is AnsiString(CP_ACP)
// AnsiStrB is AnsiString(CP_ACP)
Utf8StrA:=AnsiToUtf8(AnsiStrA); // 195 179
Utf8StrB:=AnsiToUtf8(AnsiStrB); // 65
// is Utf8StrA now utf8string? or something similar like Ansistring(UTF_8)
// is Utf8StrB now utf8string? or something similar like Ansistring(UTF_8)
Utf8StrConcat:=Utf8StrA+Utf8StrB;
// AnsiString(CP_ACP) = UTF8 + UT8
// automatic Conversion to ansiString(CP_ACP) ?
end;
--
Saludos
Santi
svaa at ciberpiula.net
More information about the fpc-pascal
mailing list