On Sun, 6 Feb 2022, James Richters via fpc-pascal wrote:

I'm trying to get Comma Delimited Text from a CSV File created with
Microsoft Excel into a string list, but I keep getting spaces as delimiter
characters.  How can I prevent this and use ONLY commas as delimiters?
I hardcoded a test string in and it is delimiting on spaces and commas, but
I wand only commas to be considered delimters.
I defined my delimiter character as , and used StrictDelmiter.  How can I
stop considering spaces as delimters?

Here is my code:
        CSVLineStringList:=TStringlist.Create;
        CSVLineStringList.Delimiter:=',';
        CSVLineStringList.StrictDelimiter;

This must be

CSVLineStringList.StrictDelimiter:=True;

But for the love of god, please stop using stringlist for CSV.
it's really not meant for that.

Use the TCSVDocument or TCSVParser/TCSVBuilder. They are much better at handling CSV data.

In the upcoming release they will be documented, but you can preview the
documentation here:
https://www.freepascal.org/daily/doc/fcl/csvreadwrite/index.html
https://www.freepascal.org/daily/doc/fcl/csvdocument/index.html



Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to