The following code snippet demonstrates how a developer can parse strings from within strings. NOTE: This code was graciously provided by a WEB forum member many years ago. Although it lacks error handling, it is an invaluable tool. |
Function GetToken(strFrom As String, intWhich As Integer, strSeparator As String) '******************************************************************* ' Pull the requested token from strFrom, delimited by ' strSeparator. ' Example: GetToken("23,34,45,56,67", 3, ",") ' would return "45" ' Example: GetToken("This is a test of how this works", 4, " ") ' would return "test" '******************************************************************* Dim intPos As Integer Dim intPos1 As Integer Dim intcount As Integer intPos = 0 For intcount = 0 To intWhich - 1 intPos1 = InStr(intPos + 1, strFrom, strSeparator) If intPos1 = 0 Then intPos1 = Len(strFrom) + 1 End If If intcount <> intWhich - 1 Then intPos = intPos1 End If Next intcount If intPos1 > intPos Then GetToken = Mid$(strFrom, intPos + 1, intPos1 - intPos - 1) Else GetToken = Null End If End Function