[fpc-pascal] Weird string behavior
Petr Kohut
mail at petr-kohut.cz
Sat Jul 23 07:41:24 CEST 2016
Hello,
I tested the program listed below in "Delphi 10.1 Berlin" with the
results shown in the comments.
PK
program Project3;
{$APPTYPE CONSOLE}
{$R *.res}
var
AnsiStrA: AnsiString;
ResultA: AnsiString;
begin
Writeln('Not Initialized');
Writeln(' AnsiStrA: ', StringCodePage(AnsiStrA)); // 1250
Writeln(' ResultA: ', StringCodePage(ResultA)); // 1250
Writeln;
Writeln('AnsiStrA := '' ''');
AnsiStrA := ' ';
Writeln(' AnsiStrA: ', StringCodePage(AnsiStrA)); // 1250
Writeln;
Writeln('AnsiStrA[1] := #243; // o acute win-1252');
AnsiStrA[1] := #243; // o acute win-1252
Writeln(' AnsiStrA: ', StringCodePage(AnsiStrA)); // 1250
Writeln;
Writeln('ResultA := AnsiStrA');
ResultA := AnsiStrA;
Writeln(' ResultA: ', StringCodePage(ResultA)); // 1250
Writeln;
Writeln('ResultA := AnsiStrA + '' ''');
ResultA := AnsiStrA + ' ';
Writeln(' ResultA: ', StringCodePage(ResultA)); // 1250
Writeln;
Writeln('ResultA := AnsiToUtf8(AnsiStrA);');
ResultA := AnsiToUtf8(AnsiStrA);
Writeln(' ResultA: ', StringCodePage(ResultA)); // 65001
Writeln;
Writeln('ResultA := AnsiToUtf8(AnsiStrA) + AnsiToUtf8(AnsiStrA);');
ResultA := AnsiToUtf8(AnsiStrA) + AnsiToUtf8(AnsiStrA);
Writeln(' ResultA: ', StringCodePage(ResultA)); // 65001
Writeln;
Writeln('ResultA := AnsiToUtf8(AnsiStrA) + AnsiStrA;');
ResultA := AnsiToUtf8(AnsiStrA) + AnsiStrA;
Writeln(' ResultA: ', StringCodePage(ResultA)); // 65001
Writeln;
Writeln('ResultA := AnsiStrA + AnsiToUtf8(AnsiStrA);');
ResultA := AnsiStrA + AnsiToUtf8(AnsiStrA);
Writeln(' ResultA: ', StringCodePage(ResultA)); // 1250
Readln;
end.
(*
Not Initialized
AnsiStrA: 1250
ResultA: 1250
AnsiStrA := ' '
AnsiStrA: 1250
AnsiStrA[1] := #243; // o acute win-1252
AnsiStrA: 1250
ResultA := AnsiStrA
ResultA: 1250
ResultA := AnsiStrA + ' '
ResultA: 1250
ResultA := AnsiToUtf8(AnsiStrA);
ResultA: 65001
ResultA := AnsiToUtf8(AnsiStrA) + AnsiToUtf8(AnsiStrA);
ResultA: 65001
ResultA := AnsiToUtf8(AnsiStrA) + AnsiStrA;
ResultA: 65001
ResultA := AnsiStrA + AnsiToUtf8(AnsiStrA);
ResultA: 1250
*)
------ Původní zpráva ------
Od: "Bart" <bartjunk64 at gmail.com>
Komu: "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org>
Odesláno: 23.07.2016 0:29:32
Předmět: Re: [fpc-pascal] Weird string behavior
>On 7/22/16, Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:
>
>>> ResultA := AnsiToUTF8(AnsiStrA + AnsiStrA); // UTF-8 ResultB :=
>>> AnsiToUTF8(AnsiStrA) + AnsiToUTF8(AnsiStrA); // Win-1252
>>>
>>>
>>> And resultA is not equal to ResultB
>>>
>>> It doesn't look like too intuitive.
>>
>> It would be good if someone with access to Delphi 2009+ could test
>>this.
>
>I asked on Dutch Delphi forum if someone could test with D2009 or up.
>
>Bart
>_______________________________________________
>fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
More information about the fpc-pascal
mailing list