[fpc-pascal] Weird string behavior

Mattias Gaertner nc-gaertnma at netcologne.de
Tue Jul 26 00:47:41 CEST 2016


On Mon, 25 Jul 2016 23:23:23 +0200
Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:

> On 25/07/16 23:07, Mattias Gaertner wrote:
> > DefaultSystemCodePage = 1252
> > s3 = "abcdef" cp = 65001  
> 
> Thanks. So the rule for concatenation appears to be:
> * the dynamic code page of the result of a string concatenation is that 
> of the left operand (except if it's an empty string, then it's that of 
> the right operand)
> * the declared code page of the final concatenation result is that of 
> the left operand

Here are some more hints:

{$APPTYPE CONSOLE}

type
   tcp866 = type ansistring(866);

var
   s1, s2: tcp866;
   u1: UTF8String;
   r1: RawByteString;
begin
   s1:='abc';
   setcodepage(rawbytestring(s1),65001,false);
   Writeln('s1 = "', s1, '" cp = ', StringCodePage(s1));
   u1:='nop';
   Writeln('u1 = "', u1, '" cp = ', StringCodePage(u1));
   s2:=s1+u1;
   Writeln('s2 = "', s2, '" cp = ', StringCodePage(s2));
   s2:=u1+s1;
   Writeln('s2 = "', s2, '" cp = ', StringCodePage(s2));
   r1:=s1+u1;
   Writeln('r1 = "', r1, '" cp = ', StringCodePage(r1));
   r1:=u1+s1;
   Writeln('r1 = "', r1, '" cp = ', StringCodePage(r1));
   readln;
end.

s1 = "abc" cp = 65001
u1 = "nop" cp = 65001
s2 = "abcnop" cp = 866
s2 = "nopabc" cp = 866
r1 = "abcnop" cp = 1252
r1 = "nopabc" cp = 1252


Mattias



More information about the fpc-pascal mailing list