Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-11

TStringList.DelimitedText seems not to work...

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

FPC 3.0.4 with Lazarus 1.8.0 on Windows 7 x64

I am trying to use TStringList containers for parsing out values of this kind for sending to a database handler script:

2018-09-02 17:37:19<TAB>1<TAB>34.0<TAB>27.6
(<TAB> = #9)

I am using this construct, where Data holds the values in the format shown above:

  Parse := TStringList.Create;
  try
    Parse.Delimiter := #9;
    Parse.DelimitedText := Data; //Expected to split to 4 values
    p := Parse.Count;
    if p < 4 then //p is actually 5 here!
      exit;
    readtime := Parse[0]; //This only gets the date part
    source := Parse[1]; //And the time winds up here!
    temp := Parse[2];
    humid := Parse[3];
    Result := AddReading(readtime, source, temp, humid);

So what happens here is that DelimitedText actually splits the string on #9 AND <whitespace>!!!!

How can I stop it from parsing using space, I thought taht whan I defined it to be <TAB> (#9) that would be what it should use....

(I think it has been mentioned here in the last year, but I cannot find it)

Bo Berglund Developer in Sweden
Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 29 lines
FPC 3.0.4 with Lazarus 1.8.0 on Windows 7 x64 I am trying to use TStringList containers for parsing out values of this kind for sending to a database handler script: 2018-09-02 17:37:19<TAB>1<TAB>34.0<TAB>27.6 (<TAB> = #9) I am using this construct, where Data holds the values in the format shown above: Parse := TStringList.Create; try Parse.Delimiter := #9; Parse.DelimitedText := Data; //Expected to split to 4 values p := Parse.Count; if p < 4 then //p is actually 5 here! exit; readtime := Parse[0]; //This only gets the date part source := Parse[1]; //And the time winds up here! temp := Parse[2]; humid := Parse[3]; Result := AddReading(readtime, source, temp, humid); So what happens here is that DelimitedText actually splits the string on #9 AND <whitespace>!!!! How can I stop it from parsing using space, I thought taht whan I defined it to be <TAB> (#9) that would be what it should use....
Set
Parse.StrictDelimiters:=True;

Michael.

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote 6 lines
> How can I stop it from parsing using space, I thought taht whan I > defined it to be <TAB> (#9) that would be what it should use.... Set Parse.StrictDelimiters:=True;

Thanks so much!

    Parse.Delimiter := #9;
    Parse.StrictDelimiter := true;
    Parse.DelimitedText := Data;
    p := Parse.Count;

Now p=4 like it should be and the database insert works OK.

If I do not set the StrictDelimiter, what is the delimitedtext breaking on?

Whitepace, line breaks and what else?

Bo Berglund Developer in Sweden