Dear Phil,
Unfortunately split wont work in the case of a comma in between 2 quotes. I'm not quite sure what you mean by the Text ODBC driver or if I could use this in a shred hosting environment.
I wrote this over the weekend it needs a little more work but I could use some input before continuing.
thanks,
Sam Lewitan
'::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::
':::
'::: Function: Parse_CVS(text)
'::: AUTHOR: S. Lewitan
'::: WebSite:
www.ebcpro.com
'::: DATE: Sep-2004
'::: PURPOSE: Excepts a comma delimited file and returns a two
'::: dimensional array.
':::
'::: Note: Please fell free to use and improve. EBC Programming, Inc.
'::: excepts no liability for the code herein.
':::
'::: (C)2003 EBC Programming, Inc.
':::
'::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::
'Excepts a comma delimited file
Function Parse_CVS(text)
bfirstLine = true
arryLines = split(text,chr(13))
xCt = ubound(arryLines)
for arryCt = 0 to xCt - 1
if len(arryLines(arryCt)) > 0 then
arrySections = Parse_ComaDelimLine(arryLines(arryCt))
if bfirstLine then
'I only call redimm once inorder to protect the info and save on time
redim arryCSV(xCt,ubound(arrySections))
bfirstLine = false
end if
for yCt = 0 to ubound(arrySections)
arryCSV(arryCt,yCt) = arrySections(yCt)
next
end if
next
Parse_CVS = arryCSV
End Function
'Excepts a comma delimited line form Function Parse_CVS
Function Parse_ComaDelimLine(strLine)
ResultsList = ""
bInTheMiddle = false
'I reconstruct the comma delimited line protecting the commas and quotes which
'need to keepted with my own delimiter and then repslit it.
MyDelim = "|~|~|"
aQuote = chr(34)
LineLen = len(strLine)
for LenCt = 1 to LineLen
aChr = mid(strLine,LenCt,1)
if (aChr <> ",") and (aChr <> aQuote) then
ResultsList = ResultsList & aChr
else
if (aChr = ",") and (bInTheMiddle = false) then
ResultsList = ResultsList & MyDelim
elseif (aChr = ",") and (bInTheMiddle = true) then
ResultsList = ResultsList & aChr
end if
if (aChr = aQuote) and (LenCt <> LineLen) then
if (bInTheMiddle = true) then
if (mid(strLine,LenCt+1,1) = aQuote) then '("")
ResultsList = ResultsList & aChr
LenCt = LenCt + 1 'Ignore next "
else
bInTheMiddle = false
end if '(mid(strLine,ct+1,1) = aQuote)
else 'meanning (bInTheMiddle = false)
if (mid(strLine,LenCt+1,1) = aQuote) then
ResultsList = ResultsList & aChr
LenCt = LenCt + 1 'Ignore next "
else
bInTheMiddle = true
end if
end if '(bInTheMiddle = true)
end if '(aChr = aQuote) and (LenCt < LineLen - 1)
end if '(aChr <> ",") or (aChr = aQuote)
next
Parse_ComaDelimLine = split(ResultsList,MyDelim)
End Function