Discussion:
[fpc-pascal] TStringList.DelimitedText seems not to work...
Bo Berglund
2018-11-19 21:09:02 UTC
Permalink
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 - fpc-***@lists.freepascal.org
http://lists.freepas
Michael Van Canneyt
2018-11-19 21:12:56 UTC
Permalink
Post by 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
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
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 - fpc-***@lists.freepascal.org
http://
Bo Berglund
2018-11-19 22:30:50 UTC
Permalink
On Mon, 19 Nov 2018 22:12:56 +0100 (CET), Michael Van Canneyt
Post by Michael Van Canneyt
Post by Bo Berglund
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 - fpc-***@lists.freepascal.org
http://lists.f
Loading...