TStringHelper.Remove is defined as follows:

TStringHelper.Remove is defined as follows:

function TStringHelper.Remove(StartIndex, Count: Integer): string;
begin
Result := Self;
System.Delete(Result, StartIndex + 1, Count);
end;

Is the + 1 by design or a bug? In C# the character at StartIndex is removed. For instance:
a := '1234';
ShowMessage(a.Remove(1,2));
ShowMessage(a.Remove(a.Length));

What do you expect to get? Guess what you get.

Comments

  1. Markus Kinzler So it is by design. StringHelper routines expect zero-based indices, irrespective of the ZEROBASEDSTRINGS setting of the calling code. Surprising I must say. However, I now see that this is documented.

    ReplyDelete
  2. What is "nice" is that debugger visualizer will not look at ZEROBASEDSTRINGS but is 0-based for mobile and 1-based for desktop.
    But what can a debugger visualizer show for s1[1] for this code?
    s2 := {$ZEROBASEDSTRINGS ON}s1[0]+{$ZEROBASEDSTRINGS OFF}s1[2];

    ReplyDelete
  3. Cristian Peța that so much sounds like the support for `with` in the debugger: nonexistent.
    Like after more than 3 decades since Turbo Pascal supported `with` no sensible programmer would use `with`.

    ReplyDelete

Post a Comment