Contents

Properties

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 Object Pascal mobile compilers (DCCIOS32 and DCCIOSARM) introduce 0-based indexing for strings. The Object Pascal desktop compilers continue to support 1-based strings, but interfaces and dynamic arrays are 0-based for all Object Pascal compilers. This change is further discussed in Migrating Object Pascal 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 Object Pascal Compilers

Object Pascal Compilers

String Indexing

Object Pascal mobile compilers

DCCIOSARM

DCCIOS32

0-based

(the starting index of the first character in a string is zero)

Object Pascal desktop compilers

DCC32

DCC64

DCCOSX

1-based

(the starting index of the first character in the string is one)

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:

varMyString:String;beginMyString:='This is a string.';Writeln(myString.IndexOf('a',0,0));//Working with zero-based or 1-based stringsWriteln(Pos('a',myString));//Working with 1-based stringsend.

Output:

8
9

Note: You are encouraged to move to the TSringHelper methods when manipulating strings on all platforms. To preserve backward compatibility with existing code as much as possible, the longstanding functions in the System unit that deal with string indices will continue to function with 1-based strings, and also perform the necessary automatic conversions to do the correct operations on 0-based strings as well. One example is System.Pos. However, these older System unit string-handling functions are deprecated and support might be removed in the future.