Hi All, I wrote a parser last week. It is very fast. Wanna try the code? It is written in VB. Code: Public Function fParseString(strString As String, lTokenNr As Long, _ strDelim As String, Optional bIncDelim As Boolean = False) As String Dim RetVal As String Dim lStartPos As Long Dim lDelimPos As Long Dim x As Long Dim lLenDelim As Long lLenDelim = Len(strDelim) lStartPos = 1 For x = 0 To lTokenNr lDelimPos = InStr(lStartPos, strString, strDelim) If lDelimPos = 0 Then RetVal = Mid(strString, _ lStartPos - IIf(bIncDelim = False, _ 0, _ lLenDelim), _ (Len(strString) + 1) - lStartPos) Exit For ElseIf x = lTokenNr Then RetVal = Mid(strString, _ lStartPos, _ IIf(bIncDelim = False, _ lDelimPos - lStartPos, _ (lDelimPos - lStartPos) + lLenDelim)) Exit For End If lStartPos = lDelimPos + lLenDelim Next x fParseString = RetVal End Function
I've never used VB before, but it looks to me like you send it two strings, your data and your delimiter, and it splits it up according to the delimiter and gives it back to you. I think it's like php's explode();
It will parse a string. You pass the string that you want to parse, give the token number, the delimiter and you can choose if you want to add the delimiter to the token or not. for example: Code: Private sub s() Dim s as string s = fParseString("a b c d", 1, " ",true) end sub "b " will be returned
Well actually it does not split a string up. It checks if there are delimiters in the string with Instr. If so the function checks if its the correct token. If not it searches for the next delimiter. It is quite efficient because it doesnt use split. Split uses a lot of memory if the data to be parsed is large. Also my parser only loops once through the entire string. Another thing that I find handy is that tokens start with 0 instead of 1.