Overload List
| # | Signature | Description |
|---|---|---|
| 1 | class operator Explicit(const Value: Char): Substring; | |
| 2 | class operator Explicit(const [ref] Value: Substring): PChar; | Conversion to PChar: the pointer ToPChar returns, nothing copied. |
| 3 | class operator Explicit(const Value: Substring): string; | |
| 4 | class operator Explicit(const Value: string): Substring; | Explicit conversions from a string or a Char, and to a string; each copies the text. |
Overload 1: class operator Explicit(const Value: Char): Substring;
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Char |
Returns: Substring
Overload 2: class operator Explicit(const [ref] Value: Substring): PChar;
Conversion to PChar: the pointer ToPChar returns, nothing copied.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Substring |
Returns: PChar
The text is terminated by #0 and the pointer is valid until the string next changes. A #0 already after the text is used as it is; where it cannot be placed without overwriting a character or taking memory, as after a window inside a longer text, ESubstringInPlaceError is raised, and MakeUnique first makes the conversion work. The conversion is explicit only, as string(s) is, so a Substring never becomes a string unseen.
A Substring passed as a C string.
uses Substr;
procedure Example;
var s: Substring;
P: PChar;
begin
s := Substring('abc');
P := PChar(s);
Assert((P = s.Data) and (P[3] = #0));
end;
Overload 3: class operator Explicit(const Value: Substring): string;
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | Substring |
Returns: string
A Substring passed as a C string.
uses Substr;
procedure Example;
var s: Substring;
P: PChar;
begin
s := Substring('abc');
P := PChar(s);
Assert((P = s.Data) and (P[3] = #0));
end;
Overload 4: class operator Explicit(const Value: string): Substring;
Explicit conversions from a string or a Char, and to a string; each copies the text.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Value | string |
Returns: Substring
A string or a character is copied into a new value, inline when it fits. string(s) copies the window into a new string. Methods and operators that take a string read it in place without a conversion; Adopt and Subrange view a string without copying it.
Copying in and out.
uses Substr;
procedure Example;
var s: Substring;
t: string;
begin
s := Substring('hello');
t := string(s);
Assert(t = 'hello');
s := Substring(Char('x'));
Assert(s.Length = 1);
end;