CorString: LastIndexOfAny |
Reports the zero-based index of the first occurrence in s of any character in a specified array of Unicode characters. The search starts at a specified character position and examines a specified number of character positions.
Public Function LastIndexOfAny( ByRef s As String, ByRef OfAny As Variant, Optional ByRef StartIndex As Variant, Optional ByRef Count As Variant ) As Long
Index numbering starts from zero.
This method begins searching at the StartIndex character position of s and proceeds backward toward the beginning until either a character in AnyOf is found or Count character positions have been examined. The search is case-sensitive.
The search for AnyOf is case-sensitive.
Exception | Condition |
---|---|
ArgumentNullException | AnyOf is uninitialized. |
ArgumentOutOfRangeException |
s does not equal "", and Count or StartIndex is negative. -or- s does not equal "" and StartIndex minus Count specifies a position that is not within s. |
The following example finds the index of the last occurrence of any character in the string "aid" within a substring of another string.
Public Sub Main() Const Br1 As String = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-" Const Br2 As String = "0123456789012345678901234567890123456789012345678901234567890123456" Const Str As String = "Now is the time for all good men to come to the aid of their party." Const Target As String = "aid" Dim Start As Long Dim At As Long Dim Count As Long Start = (Len(Str) - 1) * 2 \ 3 Count = (Len(Str) - 1) \ 3 Debug.Print CorString.Format("The first character occurrence from position {0} for {1} characters.", Start, Count) Debug.Print CorString.Format("{0}{1}{0}{2}{0}{3}{0}", Environment.NewLine, Br1, Br2, Str) Debug.Print CorString.Format("A character in '{0}' occurs at position: ", Target); At = CorString.LastIndexOfAny(Str, Target, Start, Count) If At > -1 Then Debug.Print At Else Debug.Print "(not found)" End If End Sub ' This example produces the following output. ' ' The first character occurrence from position 44 for 22 characters. ' ' 0----+----1----+----2----+----3----+----4----+----5----+----6----+- ' 0123456789012345678901234567890123456789012345678901234567890123456 ' Now is the time for all good men to come to the aid of their party. ' ' A character in 'aid' occurs at position: 27