Function Get_After_Seperator (ByVal strString As String, _
ByVal intNthOccurance As Integer, _ ByVal strSeperator As String) As String Dim intIndex As Integer Dim intStartOfString As Integer Dim intEndOfString As Integer Dim boolNotFound As Integer 'check for intNthOccurance = 0--i.e. first one If (intNthOccurance = 0) Then If (InStr(strString, strSeperator)>0) Then Get_After_Seperator = Left(strString, _ InStr(strString, strSeperator) - 1) else Get_After_Seperator = strString End If Else 'not the first one 'init start of string on first comma intStartOfString = InStr(strString, strSeperator) 'place start of string after intNthOccurance-th 'comma (-1 since already did one boolNotFound = 0 For intIndex = 1 To intNthOccurance - 1 'get next comma intStartOfString = InStr(intStartOfString + 1, _ strString, strSeperator) 'check for not found If (intStartOfString = 0) Then boolNotFound = 1 End If Next intIndex 'put start of string past 1st comma intStartOfString = intStartOfString + 1 'check for ending in a comma If (intStartOfString > Len(strString)) Then boolNotFound = 1 End If If (boolNotFound = 1) Then Get_After_Seperator = "NOT FOUND" Else intEndOfString = InStr(intStartOfString, _ strString, strSeperator) 'check for no second comma (i.e. end of string) If (intEndOfString = 0) Then intEndOfString = Len(strString) + 1 Else intEndOfString = intEndOfString - 1 End If Get_After_Seperator = Mid$(strString, _ intStartOfString, intEndOfString - _ intStartOfString + 1) End If End If End Function Inputs:intNthOccurance--seperator after which the routine will search i.e. intNthOccurance=2 will find the String after the 2nd seperator Returns: returns string or NOT FOUND if item doesn't exist Assumes:assumes strSeperator = 1 character only |