VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "StringIndex" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit Private Const NOT_FOUND = -1 Private Where_ As String Private What_ As String Private Index_ As Long Private Sub Class_Initialize() Index_ = NOT_FOUND End Sub Friend Property Let Where(ByVal Value As String) Where_ = Value End Property Friend Property Let What(ByVal Value As String) What_ = Value End Property Friend Property Let Index(ByVal Value As Long) Index_ = Value End Property Private Function Validate(ByVal Name As String, ByVal Value As Long) As Long If Value < 0 Then Err.Raise "[" & Value & "] cannot be negative!" Validate = Value End Function Public Property Get Found() As Boolean Attribute Found.VB_UserMemId = 0 Found = Index_ <> NOT_FOUND End Property Public Property Get What() As String If Index_ = NOT_FOUND Then Exit Property What = Mid$(Where_, Index_, Len(What_)) End Property Public Function Before() As String If Index_ = NOT_FOUND Then Exit Function Before = Mid$(Where_, 1, Index_ - 1) End Function Public Function After() As String If Index_ = NOT_FOUND Then Exit Function Dim Start As Long: Start = Len(What_) + Index_ If Start > Len(Where_) Then Exit Function After = Mid$(Where_, Start) End Function Public Function TakeBackward(ByVal Count As Long, Optional ByVal Skip As Long) As String Count = Validate("count", Count) Skip = Validate("skip", Skip) If Count = 0 Or Index_ = NOT_FOUND Then Exit Function Dim Start As Long: Start = Index_ - Count - Skip If Start < 1 Then Start = 1 Count = Index_ - Start - Skip If Count <= 0 Then Exit Function If Start + Count >= Len(Where_) Then Count = Len(Where_) - Start TakeBackward = Mid$(Where_, Start, Count) End Function Public Function TakeForward(ByVal Count As Long, Optional ByVal Skip As Long) As String Count = Validate("count", Count) Skip = Validate("skip", Skip) If Count = 0 Or Index_ = NOT_FOUND Then Exit Function Dim Start As Long: Start = Index_ + Len(What_) + Skip If Start >= Len(Where_) Then Exit Function If Start + Count >= Len(Where_) Then Count = Len(Where_) - Start TakeForward = Mid$(Where_, Start, Count) End Function