System.SysUtils.TStringHelper.IndexOfAny

提供: RAD Studio API Documentation
移動先: 案内検索

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


説明

指定された文字がこの文字列内で最初に現れる位置を示す整数を返します。

IndexOfAny は、次の任意のパラメータを使用します:

  • StartIndex: この文字列において、検索を開始する初期オフセットを示します。
  • CountStartIndex から開始して検索する最大長を指定します。 文字列の長さによって制限されます。

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'

関連項目