Recent

Author Topic: [solved] comma delimited text  (Read 1659 times)

speter

  • Sr. Member
  • ****
  • Posts: 349
[solved] comma delimited text
« on: January 26, 2021, 02:39:58 am »
G'Day Folks,

I am having a strange result when reading a test file, which contains a single line of 6 comma delimited numbers:
35,1, 33,5, 24,9

Code: Pascal  [Select][+][-]
  1. var
  2.   list1 : tstringlist;
  3.   list2 : tstringlist;
  4. begin
  5.   list1 := tstringlist.create;
  6.   list1.Delimiter:=',';
  7.   list1.LoadFromFile('test.txt');
  8.  
  9.   memo1.append('list1.DelimitedText='+list1.DelimitedText);
  10.   memo1.append('list1.commatext='+list1.CommaText);
  11.   memo1.append('list1.count='+list1.count.tostring);
  12.   memo1.append('list1[0]='+list1[0]);
  13.   memo1.append('');
  14.   list1.free;
  15.  
  16.   list2 := tstringlist.create;
  17.   list2.Delimiter := ',';
  18.   list2.DelimitedText := '35,1, 33,5, 24,9';
  19.  
  20.   memo1.append('list2.DelimitedText='+list2.DelimitedText);
  21.   memo1.append('list2.commatext='+list2.CommaText);
  22.   memo1.append('list2.count='+list2.count.tostring);
  23.   memo1.append('list2[0]='+list2[0]);
  24.   list2.Free;
  25. end;

The program produced the following output:
Code: [Select]
list1.DelimitedText="35,1, 33,5, 24,9"
list1.commatext="35,1, 33,5, 24,9"
list1.count=1
list1[0]=35,1, 33,5, 24,9

list2.DelimitedText=35,1,33,5,24,9
list2.commatext=35,1,33,5,24,9
list2.count=6
list2[0]=35

Note that - for list1 - the delimitedtext is in quotes and the count=1. Setting StrictDelimiter:=false (or true) has no impact.
Whereas - for list2 - the text is not quoted and count=6.

Can someone please tell me what I am doing wrong with list1!?

cheers
S.
« Last Edit: January 26, 2021, 02:49:49 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

speter

  • Sr. Member
  • ****
  • Posts: 349
Re: comma delimited text
« Reply #1 on: January 26, 2021, 02:49:33 am »
I fixed my issue by including the following after loading from the file (line 8 ):
Code: Pascal  [Select][+][-]
  1. list1.DelimitedText := list1.text;

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

 

TinyPortal © 2005-2018