System.SysUtils.TStringHelper.IndexOfAny
Delphi
function IndexOfAny(const AnyOf: array of Char): Integer; overload;
function IndexOfAny(const AnyOf: array of Char; StartIndex: Integer): Integer; overload;
function IndexOfAny(const AnyOf: array of Char; StartIndex: Integer; Count: Integer): Integer; overload;
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
function | public | System.SysUtils.pas | System.SysUtils | TStringHelper |
Description
Returns an integer indicating the position of the first given character found in the string.
IndexOfAny uses the following optional parameters:
StartIndex
: It specifies the initial offset in this string where the search starts.Count
: It specifies the maximum length to search starting fromStartIndex
. It is limited by the string length.
IndexOfAny returns -1 if:
- The given character is not found.
StartIndex
specifies a value higher than the string length minus 1 (it is a 0-based parameter).Count
is equal to or less than 0.
Example
var
MyString: String;
begin
MyString := 'This is a string.';
Writeln(MyString.IndexOfAny(['w']));
Writeln(MyString.IndexOfAny(['w', 's', 'a'], 0));
Writeln(MyString.IndexOfAny(['w', 's', 'a'], 9));
Writeln(MyString.IndexOfAny(['w', 's', 'a'], 11, 4));
end.
Output:
-1 // 'w' is not present in MyString 3 // The first given character found is 's' in position 3 10 // Staring at position 9, the first given character found is 's' at position 10 -1 // No given characters are found in the substring 'trin'