I'm using the TStringHelper
in a Win32 Application, but when I try to access a particular char or get a substring the values returned are not the same If I use the equivalent old string functions.
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils;
var
i : Integer;
s : string;
begin
try
i:=12345678;
Writeln(i.ToString().Chars[1]); // returns 2
Writeln(i.ToString().Substring(1)); //returns 2345678
s:=IntToStr(i);
Writeln(s[1]); //returns 1
Writeln(Copy(s,1,Length(s)));//returns 12345678
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.
The question is Why the TStringHelper functions are not equivalent to the old string functions?
This is because all the methods and properties of the System.SysUtils.TStringHelper are zero based index, this helper was compiler with the {$ZEROBASEDSTRINGS ON} directive. you can find more info in the System.SysUtils.TStringHelper documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With