But for me that is kind of inconsistency, in my opinion. If usually arrays start with 0, then string is no different array, why it has to start with 1?
Please ask professor Wirth, who invented Pascal
Also, I would expect the same command (I mean high() ) with the same given arguments produce the same result, but if plain executed it gives 255, if in loop it gives something else. Not sure if that is right.....
Your program does not specify Delphi mode, nor does it specify {$H+} (longstrings on).
So your strings are ShortStrings, which have a size of 256 bytes (0..255), always.
So Low(ShortString) will be 0, High(ShortString) will be 255.
For AnsiStrings Low() will will be 1, High() will be the same as Length().
{$H+}
var
A: String;
S: ShortString;
begin
A := 'foo';
S := 'foo';
writeln('Low(A)=',Low(A),', High(A)=',High(A));
writeln('Low(S)=',Low(S),', High(S)=',High(S));
A := '';
S := '';
writeln('Low(A)=',Low(A),', High(A)=',High(A));
writeln('Low(S)=',Low(S),', High(S)=',High(S));
end.
Outputs
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
Low(A)=1, High(A)=3
Low(S)=0, High(S)=255
Low(A)=1, High(A)=0
Low(S)=0, High(S)=255
Length() also works on dynamic arrays.
Notice that arrays can start with any index, and Low/High will still give you the correct answers.
Bart