TStringHelper = record helper for string
struct TStringHelper /* Helper for uni string 'System::UnicodeString' */;
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
Delphi desktop compilers
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.
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.