Does anyone have a fast string parser for Access VBA
Printable View
Does anyone have a fast string parser for Access VBA
dpends what your parsing for, and what your strings like and how long it is
For VBA & VB5 that don't have a Split function - this breaks a long string into fields (array elements) based on a separator character like space or | (pipe) or whatever
From Aaron Young
Code:Private Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
'Written by Aaron Young
Dim sParts() As String
Dim lParts As Long
Dim lPos As Long
lPos = InStr(sString, sSeparator)
While lPos
ReDim Preserve sParts(lParts)
sParts(lParts) = Left(sString, lPos - 1)
sString = Mid(sString, lPos + Len(sSeparator))
lPos = InStr(sString, sSeparator)
lParts = lParts + 1
Wend
If Len(sString) Then
ReDim Preserve sParts(lParts)
sParts(lParts) = sString
End If
Split2 = IIf(lParts, sParts, Array())
End Function
Hi all,
Thankyou for replying. The problem is as follows:
If have a text file (about 800k) and its full of text. The text has field delimiters (<~>) and recorddelimiters (<---NEXT--->) dont ask me why they are chosen as they are......Every record has 34 fields.
I need to parse the textfile twice: First get all recorddelimiters and then parse the string using the fieldelimters. Then all the seperate tokes need to be inserted with a recordset.
Any ideas?