TStringList - Strange quotation mark handling

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

TStringList - Strange quotation mark handling

Gabor Boros-2
Hi All,

With the attached example program and data.csv I got the next result:

0 * 84392
1 * asfds
2 * hytr
3 * 43421454
4 * O
5 *  fdsfds
6 * 654645645 "O" fdsfsd
7 * hgfgfedw
8 * fg
9 * 321.544
10 * 89
11 * 0


"O" fdsfds - broken into two parts which is bad from my POV. See 4 * O
and 5 *  fdsfds. Why?

Gabor

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

data.csv (118 bytes) Download Attachment
SL.pas (354 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TStringList - Strange quotation mark handling

Kevin Jesshope
Setting the quotechar to something impossible (linefeed, #0 etc) stops the quote processing.

  SL2.QuoteChar:=#10;

results in

0 * 84392
1 * asfds
2 * hytr
3 * 43421454
4 * "O" fdsfds
5 * 654645645 "O" fdsfsd
6 * hgfgfedw
7 * fg
8 * 321.544
9 * 89
10 * 0

Regards

Kevin Jesshope - In Touch Computer Support
Supporting Aberfoyle Hub R-7 and Happy Valley Primary Schools

On Wed, Aug 16, 2017 at 9:58 PM, Gabor Boros <[hidden email]> wrote:
Hi All,

With the attached example program and data.csv I got the next result:

0 * 84392
1 * asfds
2 * hytr
3 * 43421454
4 * O
5 *  fdsfds
6 * 654645645 "O" fdsfsd
7 * hgfgfedw
8 * fg
9 * 321.544
10 * 89
11 * 0


"O" fdsfds - broken into two parts which is bad from my POV. See 4 * O and 5 *  fdsfds. Why?

Gabor

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


_______________________________________________
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 - Strange quotation mark handling

Michael Van Canneyt
In reply to this post by Gabor Boros-2


On Wed, 16 Aug 2017, Gabor Boros wrote:

> Hi All,
>
> With the attached example program and data.csv I got the next result:
>
> 0 * 84392
> 1 * asfds
> 2 * hytr
> 3 * 43421454
> 4 * O
> 5 *  fdsfds
> 6 * 654645645 "O" fdsfsd
> 7 * hgfgfedw
> 8 * fg
> 9 * 321.544
> 10 * 89
> 11 * 0
>
>
> "O" fdsfds - broken into two parts which is bad from my POV. See 4 * O and 5
> *  fdsfds. Why?

Because the quotes must be the first and last character of each string (or "cell").

As noted in another reply, set the quote character to something unused, and
it will disable (or circumvent) quoting altogether.

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 - Strange quotation mark handling

Gabor Boros-2
In reply to this post by Kevin Jesshope
2017. 08. 16. 15:15 keltezéssel, Kevin Jesshope írta:
> Setting the quotechar to something impossible (linefeed, #0 etc) stops
> the quote processing.

SL2.QuoteChar:=#0; solved my problem. Thank you!

Gabor
_______________________________________________
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 - Strange quotation mark handling

Gabor Boros-2
In reply to this post by Michael Van Canneyt
2017. 08. 16. 15:21 keltezéssel, Michael Van Canneyt írta:
> Because the quotes must be the first and last character of each string
> (or "cell").
>
> As noted in another reply, set the quote character to something unused, and
> it will disable (or circumvent) quoting altogether.

SL2.QuoteChar:=#0; solved my problem. But strange if the TStringList
think from a starting " the string is quoted. For example if data.cvs
contains "abc|89|0 I got the next result with my example program
(without QuoteChar trick): 0 * abc|89|0

Gabor
_______________________________________________
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 - Strange quotation mark handling

Graeme Geldenhuys-6
On 2017-08-16 14:48, Gabor Boros wrote:
> SL2.QuoteChar:=#0; solved my problem. But strange if the TStringList
> think from a starting " the string is quoted. For example if data.cvs
> contains "abc|89|0 I got the next result with my example program
> (without QuoteChar trick): 0 * abc|89|0

Try using tiOPF's tiUtils.pas unit. More specifically the tiNumToken()
and tiToken() functions. No quatechar tricks and such are needed. These
function can also be used independently without needing anything else
from the tiOPF framework.

  https://github.com/graemeg/tiopf/blob/tiopf2/Core/tiUtils.pas#L783..L837



Regards,
   Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
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 - Strange quotation mark handling

Benito van der Zander
In reply to this post by Gabor Boros-2
Hi,

very stupid defaults indeed.

I just had a bug last week, because I was using TStringList as map and forgot to change it to case-sensitive



Cheers,
Benito 



Am 16.08.2017 um 15:48 schrieb Gabor Boros:
2017. 08. 16. 15:21 keltezéssel, Michael Van Canneyt írta:
Because the quotes must be the first and last character of each string (or "cell").

As noted in another reply, set the quote character to something unused, and
it will disable (or circumvent) quoting altogether.

SL2.QuoteChar:=#0; solved my problem. But strange if the TStringList think from a starting " the string is quoted. For example if data.cvs contains "abc|89|0 I got the next result with my example program (without QuoteChar trick): 0 * abc|89|0

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


_______________________________________________
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 - Strange quotation mark handling

el_es
On 16/08/17 15:45, Benito van der Zander wrote:
> Hi,

[sorry I could not stop myself from reordering your top-post]

> Am 16.08.2017 um 15:48 schrieb Gabor Boros:
>> 2017. 08. 16. 15:21 keltezéssel, Michael Van Canneyt írta:
>>> Because the quotes must be the first and last character of each
>>> string (or "cell").
>>>
>>> As noted in another reply, set the quote character to something
>>> unused, and it will disable (or circumvent) quoting altogether.
>>
>> SL2.QuoteChar:=#0; solved my problem. But strange if the
>> TStringList think from a starting " the string is quoted. For
>> example if data.cvs contains "abc|89|0 I got the next result with
>> my example program (without QuoteChar trick): 0 * abc|89|0
>>
>> Gabor _______________________________________________
>
> very stupid defaults indeed.
>
> I just had a bug last week, because I was using TStringList as map
> and forgot to change it to case-sensitive
>

Because the default format of QuotedText is actually 'csv',
which goes like "field 1 = value 1","value 2","field 3"
and StringList was created to deal with that  (I think).
You can bend QuotedText to do amazing things but the quote detector
is set for the default "" here.

>
>
> Cheers, Benito
>
>
>
el es

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