TStringList.DelimitedText seems not to work...

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

TStringList.DelimitedText seems not to work...

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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TStringList.DelimitedText seems not to work...

Michael Van Canneyt


On Mon, 19 Nov 2018, Bo Berglund wrote:

> 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.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: TStringList.DelimitedText seems not to work...

Bo Berglund
On Mon, 19 Nov 2018 22:12:56 +0100 (CET), Michael Van Canneyt
<[hidden email]> wrote:

>> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal