Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV problem....

Status
Not open for further replies.

RaceAap

IS-IT--Management
Sep 5, 2001
39
NL
Hi,

I need some help with the followijng issue..

I need to import a csv file uploaded to a website into the database, the uplaod works.. but the import gives errors..

I use data = Split(readline,",") to split the readline from the csv into an array, that is where it goes wrong :S
The csv file looks like this:

"id","what","misc","date"
"1","record,1","data334345","11-11-2002"

Who can help me with this ??

Thanx
Lon
 
Is it because you've got text qualifiers (") surrounding your strings?

The " sign is chr(34), so you could create a string like this:

strSeparator = chr(34) & "," & chr(34)

and use it as your delimiter:

Split(readline,strSeparator)

but then you'd still need to strip the first " off the first string, and the final " off the last one.

I hope this is useful...

Rob
 
To remove the first and last ", you could use replace.
Code:
strSeparator = chr(34) & "," & chr(34)
asMyArray = Split(readline,strSeparator)
asMyArray(0) = replace(asMyArray, """", "") OR
asMyArray(0) = replace(asMyArray, chr(34), "")
asMyArray(ubound(asMyArray)) = replace(asMyArray(ubound(asMyArray), """", "")

If you are positive the original data will never have a " in it, you could do the replace it up front.
Code:
readline = replace(readline, """", "")
asMyArray = Split(readline, ",")
Thanks,

Gabe
 
Gabe,

Would it not be replace(readline, """, "") - three not four in the second argument?

Rob
 
Nope,

VBScript sees "" as a single quote.
The first " starts the string.
The second and third "s are turned into one " by VBScript.
The fourth " closes the string.


Thanks,

Gabe
 
Thanx for the replies, I've got it working with the code you posted here!


Thanx
Lon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top