I was looking all over for a function to do this, and what I found were a number of character-by-character routines that were slow as all get out.
So, with ebgreen's help
http://www.visualbasicscript.com/fb.aspx?m=42592 I was able to come up with a much faster solution.
This function allows me to parse through a CSV file of about 5megs in size, roughly 8,300 lines long, each line containing about 30 fields (a dump of our company's GAL from AD) in about 3.65 seconds on an Athlon 3000+.
Enjoy.
Function fParseCSV(sStringIn,sChar)
'This function takes as input, a comma-delimited string, and returns the same string
'with each "field" separated by "sChar". This is useful when dealing with a CSV file that
'only has SOME fields enclosed with quotes and others without quotes. This will provide
'a single method of separating fields for use in a Split() or other parsing in VBS.
Dim sTest, aOutput, iParts, iStart, iStop, sElement, sFinalText
sTest = Replace(sStringIn,",",sChar)
sFinalText = sTest
iParts = 0
aOutput = Array()
Do While Len(sStringIn) > 0
iStart = InStr(sTest, Chr(34))
If iStart >= 0 Then
iStop = InStr(iStart + 1, sTest, Chr(34))
If iStop > 0 Then
ReDim Preserve aOutput(iParts)
aOutput(iParts) = Mid(sTest, iStart+1, iStop - iStart-1)
iParts = iParts + 1
sTest = Mid(sTest, iStop+1)
Else
Exit Do
End If
Else
Exit Do
End If
Loop
For Each sElement In aOutput
sFinalText = Replace(sFinalText,sElement,Replace(sElement,sChar,","))
Next
fParseCSV = Replace(sFinalText,Chr(34),"")
End Function
"Would you like to touch my monkey?" - Dieter (Mike Meyers)
"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury