System.SysUtils.TStringHelper.IndexOfAny

De RAD Studio API Documentation
Aller à : navigation, rechercher

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;

Propriétés

Type Visibilité  Source Unité  Parent
function public System.SysUtils.pas System.SysUtils TStringHelper


Description

Renvoie un entier indiquant la position du premier caractère donné trouvé dans la chaîne.

IndexOfAny utilise les paramètres facultatifs suivants :

  • StartIndex : spécifie le décalage initial dans cette chaîne lorsque la recherche commence.
  • Count : spécifie la longueur maximale à rechercher à partir de StartIndex. Il est limité par la longueur de la chaîne.

IndexOfAny renvoie -1 dans la situation suivante :

  • le caractère donné est introuvable.
  • StartIndex spécifie une valeur supérieure à la longueur de la chaîne moins 1 (il s’agit d’un paramètre basé sur 0).
  • Count est égal ou inférieur à 0.

Exemple

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.

Sortie :


-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'

Voir aussi