Sign in Join

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

Mailing lists / fpc-pascal / 2017-08

TStringList - Strange quotation mark handling

8 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Gabor Boros

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

Kevin Jesshope
to Gabor Boros

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

Gabor Boros wrote 27 lines
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 - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Michael Van Canneyt
to Gabor Boros: With the attached example program and data.csv I got the next result: 0 * 84392 1 * asfds…
Gabor Boros wrote 20 lines
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.

Gabor Boros
to Michael Van Canneyt: Because the quotes must be the first and last character of each string (or "cell"). As…

2017. 08. 16. 15:21 keltezéssel, Michael Van Canneyt írta:

Show quoted text 5 lines
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

Graeme Geldenhuys
to Gabor Boros
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
Benito van der Zander
to Gabor Boros: 2017. 08. 16. 15:21 keltezéssel, Michael Van Canneyt írta: SL2.QuoteChar:=#0; solved my…

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

Gabor Boros wrote 17 lines
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 - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
el es
to Benito van der Zander
Benito van der Zander wrote
Hi,

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

Show quoted text 20 lines
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.

Show quoted text 6 lines
Cheers, Benito

el es