Filtering double-quotes and spaces in loadCSV

Tirs

Member
Licensed User
Longtime User
Hello! I'm importing a CSV file into a table (using loadCSV, of course). The file has this format:

"Name 1"; "This is the first name"; "This is another column for the first name"
"Name 2"; "This is the second name"; "This is another column for the second name"
etc...

The problem is, loadCSV cuts strings strictly at the separator character, loading everything else into the cell, including the delimiting double-quotes and even the spaces after the semicolons but out of the quotes. So, instead of the expected:

[Name 1][This is the first name][This is another column for the first name]

...I get:

["Name 1"][ "This is the first name"][ "This is another column for the first name"]

(brackets added for clarity and to show spaces inside the cells).

Yes, I know I can parse cell by cell and remove leading spaces and quotes using simple string functions, but I would like a more "elegant" solution. Anyone knows any, or can think of a more decent workaround?
Erel, maybe a new, optional "Delimiter" parameter would be a good idea for loadCSV?

P.S: I tried both comma and semi-colon as delimiters. Same results.
 

Tirs

Member
Licensed User
Longtime User
One possible solution is to read the entire file with FileReadToEnd, do a StrReplace and replace all [; ] with [,].

Hum... then, after reading the file into a big string and doing StrReplace, I would need a loop to parse the string into the table cell by cell, so I prefer to use the loop to clean the table directly. We don't have a method called "table.loadFromABigString" ! :D

Anyway, many CSV files come with string delimiters, so if you don't mind I'm going to add the idea of the extra parameter to the "Wishlist" sub-forum, for when you have the time and feel like it :)

Regards!
 

Tirs

Member
Licensed User
Longtime User
It was the spaces, not the quotes!

Thanks Erel! I got your reply. If the file has spaces:

"item1"; "item2"; "item3"...

...then the problem happens. Removing the spaces between separators the loadCSV method works fine.

Guilty me, for creating the test data manually :BangHead:
 
Top