FirstIndex, propriété

Microsoft VBScript

Microsoft® Visual Basic® Scripting Edition 
FirstIndex, propriété
 Référence du langage 
Version 5 

Voir aussi                  Application


Description
Indique la position dans une chaîne de recherche où une correspondance a été trouvée.
Syntaxe
object.FirstIndex

L'argument object représente tout objet Match.

Notes
La propriété FirstIndex utilise un décalage qui commence à zéro à partir du début de la chaîne de recherche. En d'autres termes, la première lettre de la chaîne est identifiée par le caractère zéro (0). Le code suivant montre comment utiliser la propriété FirstIndex :
Function RegExpTest(patrn, strng)
  Dim regEx, Match, Matches		' Crée la variable.
  Set regEx = New RegExp			' Crée l'expression littérale.
  regEx.Pattern = patrn			' Définit les critères.
  regEx.IgnoreCase = True			' Ignore la casse.
  regEx.Global = True			' Définit le champ d'application.
  Set Matches = regEx.Execute(strng)	' Lance la recherche.
  For Each Match in Matches		' Itère la collection Matches.
    RetStr = RetStr & "Correspondance " & I & " trouvée à la position "
    RetStr = RetStr & Match.FirstIndex & ". La valeur de la correspondance est "'
    RetStr = RetStr & Match.Value & "'." & vbCRLF
  Next
  RegExpTest = RetStr
End Function

MsgBox(RegExpTest("est.", "IS1 is2 IS3 is4"))