System.SysUtils.TStringHelper
Delphi
TStringHelper = record helper for string
C++
struct TStringHelper /* Helper for uni string 'System::UnicodeString' */;
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
helper class |
public | System.SysUtils.pas System.SysUtils.hpp |
System.SysUtils | System.SysUtils |
Description
Record helper that provides functions and properties for working with all strings, including both 1-based and 0-based strings.
TStringHelper is a record helper for the intrinsic string type and provides helper methods that are accessible from string types as if the helper methods were methods of a class or record.
The Delphi mobile compilers (DCCIOS32 and DCCIOSARM) introduce 0-based indexing for strings. The Delphi desktop compilers continue to support 1-based strings, but interfaces and dynamic arrays are 0-based for all Delphi compilers. This change is further discussed in Migrating Delphi Code to Mobile from Desktop.
Indexing for string types is different according to the compiler in use, as shown in the following table.
Indexing of Strings in the Delphi Compilers | |
---|---|
Delphi Compilers | String Indexing |
Delphi mobile compilers
|
0-based |
Delphi desktop compilers
|
1-based |
Always using TStringHelper methods to handle strings enables you to write code for multiple compilers and multiple platforms without using conditionals such as the IFDEF directive.
Example
If your code previously used the System.Pos function with a string called S, you can now edit the code to use the TStringHelper.IndexOf method. You can call S.IndexOf() to perform the same function:
var
MyString: String;
begin
MyString := 'This is a string.';
Writeln(myString.IndexOf('a', 0, 0)); //Working with zero-based or 1-based strings
Writeln(Pos('a', myString)); //Working with 1-based strings
end.
Output:
8 9