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;
プロパティ
種類 | 可視性 | ソース | ユニット | 親 |
---|---|---|---|---|
function | public | System.SysUtils.pas | System.SysUtils | TStringHelper |
説明
指定された文字が、この 0 基準の文字列内で最初に現れる場所を示す整数を返します。
IndexOfAny は、次の任意のパラメータを使用します:
StartIndex
は、検索を開始するこの 0 から始まる文字列の初期オフセットを指定します。Count
は、StartIndex
から開始して検索する最大長を指定します。文字列の長さによって制限されます。
IndexOfAny は次の場合に、-1 を返します:
- 指定された文字が見つからない。
StartIndex
に、文字列の長さから 1 を引いた値より大きい値が指定されている(0 始まり)。Count
が 0 以下。
例
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.
出力:
-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'