Welcome! Log In Create A New Profile

Advanced

Parsing a csv-file

Posted by gpredl 
Parsing a csv-file
January 11, 2021 11:04AM
Hi,

Excel, LibreOffice Calc & Co can save / export a worksheet to a CSV-file. That's fine. They're using commas as delimiters, there's no way to change that in LibreOffice Calc at least. If one or more delimiter/s are contained in an exported cell, the value is simply enclosed in apostrophes. Traversing a string read from the csv-file with fReadLine using ExtractString( ... ) is rather difficult. As an example

123,this Is the first line, "12,23"
456,"this is, btw, the second line",2450
"47,78",this is the third line,765

You see, the delimiter (comma) can appear anywhere within the line. Is there any good solution to this?

Kind regards,
Guenter Predl
office@windev.at
Argus
Re: Parsing a csv-file
January 11, 2021 12:54PM
just checked in libreoffice:
save as CSV
confirm CSV and not ODT
'Export Text File' windows open and lets you choose field delimiter and string delimiter and.... like every other calc application I have ever seen
Re: Parsing a csv-file
January 11, 2021 01:11PM
Hi Argus, thank's a lot!!

Kind regards,
Guenter Predl
office@windev.at
Re: Parsing a csv-file
January 12, 2021 07:51AM
Hi Argus,

thank you very much! You just saved me from writing hundreds of lines of code! I only looked at the csv-file that I got from our customer. Yesterday I asked him to re-export the data from their Excel and use the | character as a field separator - not the darned comma. And ho and below, the csv-file is a simple thing to read now! Thank you for your advice!

Kind regards,
Guenter Predl
office@windev.at



Edited 1 time(s). Last edit at 01/12/2021 07:52AM by gpredl.
Re: Parsing a csv-file
January 12, 2021 09:00AM
Hi all

CSV export from Excel takes the settings from the Windows Regional Settings (Option "More Settings").
In there on the "Numbers" tab you can define the "list separator" character.
If you set that to a pipe "|" Excel will export to csv with the fields separated by a "|".
At least that is how it worked in the old days.
Guess it is still the case.

Cheers

Peter Holemans
Re: Parsing a csv-file
January 12, 2021 10:59AM
Hi Peter,

yes, it still does so ... greetings!

Kind regards,
Guenter Predl
office@windev.at
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: