[fpc-pascal] Putting Delimited text into a StringList

James Richters james.richters at productionautomation.net
Sun Feb 6 23:28:34 CET 2022


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;
         CSVLineStringList.DelimitedText:='This is a test,1234,5678';
         For I := 0 to CSVLineStringList.Count-1  do
            Begin
               Writeln(I+1,':' + CSVLineStringList[I]);
            End;
         CSVLineStringList.Free;
 
Here is my output:
1:This
2:is
3:a
4:test
5:1234
6:5678
 
I am wanting the output of this to be:
1: This is a test
2: 1234
3: 5678
 
James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20220206/12b05d10/attachment-0001.htm>


More information about the fpc-pascal mailing list