Substring.Subrange Method

Overload List

#SignatureDescription
1procedure Subrange(const Src: Substring; const SrcIdx, SrcLen: Integer); overload;Views SrcLen characters of Src from SrcIdx (1-based), copying no character.
2procedure Subrange(const Src: string; const SrcIdx, SrcLen: Integer); overload;Views SrcLen characters of Src from SrcIdx, without copying them.

Overload 1: procedure Subrange(const Src: Substring; const SrcIdx, SrcLen: Integer); overload;

Views SrcLen characters of Src from SrcIdx (1-based), copying no character.

#NameTypeDescription
1SrcSubstring
2SrcIdxInteger
3SrcLenInteger

Result: stored in self (calling object)

Remarks:

The view is valid while Src lives unchanged. The range must lie inside Src, else ESubstringRangeError is raised.

Examples

The key of a key=value line, viewed in place.

uses Substr;

procedure Example;
var Line, Key: Substring;
begin
    Line := Substring('key=value');
    Key.Subrange(Line, 1, 3);
    Assert(Key = 'key');
end;

Overload 2: procedure Subrange(const Src: string; const SrcIdx, SrcLen: Integer); overload;

Views SrcLen characters of Src from SrcIdx, without copying them.

#NameDescription
1Src

The string viewed; it must live unchanged while the view is used.

2SrcIdx

The first character's position, 1-based.

3SrcLen

The number of characters.

Result: stored in self (calling object)

Remarks:

The range must lie inside Src, else ESubstringRangeError is raised.

Examples

A view of a string's value part.

uses Substr;

procedure Example;
var Text: string;
    s: Substring;
begin
    Text := 'key=value';
    s.Subrange(Text, 5, 5);
    Assert(s = 'value');
    Assert(s.IsExternal);
end;