VB6 introduced the split() function, which will return an array of strings, one for each delimited field in a string, with a user-selectable delimiter.
Given...
John Jones, 123 Main St., Dayton OH 45402
...in a string (a line collected by Line Input #1, sRecord for example), then aFields = Split(sRecord) gives these array elements in aFields...
John Jones
123 Main St.
Dayton OH 45402
...but the problem comes with real-world .CSV files, which may use quotes to surround fields containing commas as data. Given...
"John Jones, Sr.", 123 Main St., "Dayton, OH 45402"
...the Split function returns the following...
"John Jones
Sr."
123 Main St.
"Dayton
OH 45402"
...which is not useful. I have code to do the painful parsing myself at the moment, but I have to believe there's an API call somewhere, or maybe a DLL or ActiveX control one can buy or download which does this? Even VB itself contains code to parse this correctly, because if you loop through Input #1, sField statements for each field, the quoted fields will "stick together" (and the quotes are conveniently discarded), but reading such a file like that will cause your program to come completely unglued (you get out of sync with the fields) the first time you hit a record with too few or too many commas.
Has anybody seen a component one can download or buy which will assist in parsing this common file format?
Thanks.
- Chuck Somerville
Enter your message below
Sign in or Join us (it's free).