Home » String Manipulation » How to Find a String within another String with many options
How to Find a String within another String with many options
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 'String Manipulation - How to Find a String within another String with many options Option Explicit Public Function FindNext(ByVal strExpression As String, ByVal sFind As String, _ Optional ByVal lPosition As Long = 1, Optional bCaseSensitive As Boolean = False, _ Optional ByVal bSearchUp As Boolean = False) As Long Dim lPos As Long, lFind As Long If strExpression <> "" Then If lPosition < 1 Then lPosition = 1 If lPosition > Len(strExpression) Then lPosition = Len(strExpression) If bSearchUp Then lPos = lPosition - 1 While lPos > 0 lFind = InStr(lPos, strExpression, sFind, Abs(Not bCaseSensitive)) If lFind = lPos Then lPos = 0 Else lFind = 0 lPos = lPos - 1 End If Wend FindNext = lFind Else FindNext = InStr(lPosition + 1, strExpression, sFind, Abs(Not bCaseSensitive)) End If End If End Function |
Enjoy this article?
Filed under: String Manipulation
Leave a comment