 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
HD Guest
|
Posted: Tue Mar 21, 2006 3:03 pm Post subject: Using StringList for CSV file |
|
|
Hi,
I need to create a CSV file. I do not want to use Excel... because Excel is
not installed on the server and we do not want to install it.
I was thinking of using the StringList.Add for each line... and a
StringList.SavetoFile().. to save to a CSV File...
Here is my question... What is the maximum of characters I can put in each
item of a stringlist?? And what is the maximum number of items a stringlist
can have.
Thank you,
H. Dumas |
|
| Back to top |
|
 |
Uffe Kousgaard Guest
|
Posted: Tue Mar 21, 2006 4:03 pm Post subject: Re: Using StringList for CSV file |
|
|
"HD" <dumh (AT) hotmail (DOT) com> wrote in message
news:442006c1 (AT) newsgroups (DOT) borland.com...
| Quote: |
I was thinking of using the StringList.Add for each line... and a
StringList.SavetoFile().. to save to a CSV File...
|
CSV files are so easy to write: Just do it and skip using TStringList.
Regards
Uffe |
|
| Back to top |
|
 |
John Herbster Guest
|
Posted: Tue Mar 21, 2006 4:03 pm Post subject: Re: Using StringList for CSV file |
|
|
"Uffe Kousgaard" wrote
| Quote: | CSV files are so easy to write: Just do it ...
|
True.
My only problems with writing CSV files is figuring out the
internationalization issues with commas, stops, semicolons,
and quotes.
Rgds, JohnH |
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Tue Mar 21, 2006 4:03 pm Post subject: Re: Using StringList for CSV file |
|
|
"HD" <dumh (AT) hotmail (DOT) com> wrote in news:442006c1 (AT) newsgroups (DOT) borland.com:
| Quote: | What is the maximum of characters I can put in each
item of a stringlist??
|
From the help, each string (AnsiString) can hold 2^31 (2,147,483,647)
chars. If you're using WideString then it is 2^30 (1,073,741,824).
| Quote: | And what is the maximum number of items a
stringlist can have.
|
TStrings.Count is an integer, so you could reference 2,147,483,647
items. I'm not sure how well TStringList will handle it.
If you're going to be doing a lot of sorting, filtering, etc. You might
look at an in memory dataset that you can save to CSV file.
--
Iman |
|
| Back to top |
|
 |
Marco van de Voort Guest
|
Posted: Tue Mar 21, 2006 4:03 pm Post subject: Re: Using StringList for CSV file |
|
|
On 2006-03-21, HD <dumh (AT) hotmail (DOT) com> wrote:
| Quote: | Hi,
I need to create a CSV file. I do not want to use Excel... because Excel is
not installed on the server and we do not want to install it.
I was thinking of using the StringList.Add for each line... and a
StringList.SavetoFile().. to save to a CSV File...
Here is my question... What is the maximum of characters I can put in each
item of a stringlist?? And what is the maximum number of items a stringlist
can have.
|
Your memory. Keep in mind that the size of your file will be limited by the
size of the memory you have, since you first create it in mem, and then
throw it to disc.
Ordinary methods (assignfile/filestreams etc) don't have this problems. |
|
| Back to top |
|
 |
Ralf Mimoun Guest
|
Posted: Tue Mar 21, 2006 4:03 pm Post subject: Re: Using StringList for CSV file |
|
|
HD wrote:
....
| Quote: | Here is my question... What is the maximum of characters I can put in
each item of a stringlist?? And what is the maximum number of items a
stringlist can have.
|
Something about 4 gig - large enough. But I recommend something easier to
use than that, eg. SMExport.
Ralf |
|
| Back to top |
|
 |
Craig Stuntz [TeamB] Guest
|
Posted: Tue Mar 21, 2006 4:03 pm Post subject: Re: Using StringList for CSV file |
|
|
HD wrote:
| Quote: | Here is my question... What is the maximum of characters I can put in
each item of a stringlist?? And what is the maximum number of items a
stringlist can have.
|
The size of the items is limited by the size of a string, which, last
I checked, was 2 GB. The number of items is limited by the range of the
index which is a signed integer and hence is just over 2 billion.
If that's not enough for you then you probably don't want to use a
stringlist. :)
--
Craig Stuntz [TeamB] · Vertex Systems Corp. · Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
All the great TeamB service you've come to expect plus (New!)
Irish Tin Whistle tips: http://learningtowhistle.blogspot.com |
|
| Back to top |
|
 |
Jim Cooper Guest
|
Posted: Tue Mar 21, 2006 5:03 pm Post subject: Re: Using StringList for CSV file |
|
|
| Quote: | Do CSV files use periods in Europe?
|
No, but numbers use commas for decimal points
Cheers,
Jim Cooper
_____________________________________________
Jim Cooper jcooper (AT) tabdee (DOT) ltd.uk
Skype : jim.cooper
Tabdee Ltd http://www.tabdee.ltd.uk
TurboSync - Connecting Delphi to your Palm
_____________________________________________ |
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Tue Mar 21, 2006 5:03 pm Post subject: Re: Using StringList for CSV file |
|
|
John Herbster wrote:
| Quote: | My only problems with writing CSV files is figuring out the
internationalization issues with commas, stops, semicolons,
and quotes.
|
Do CSV files use periods in Europe? :)
If I don't write my own parser to chop up a string's comma separated
values, I use AnsiQuotedStr and AnsiDequotedStr to make sure any white
space or special characters are wrapped and let TStringList's CommaText
do the heavy lifting.
In Delphi 2006 (and maybe 2005?), TStringList has a StrictDelimiter
property. Set this to True and it will only use the specified
delimiter with CommaText instead of also using spaces.
--
Regards,
Bruce McGee
Glooscap Software |
|
| Back to top |
|
 |
Troy Wolbrink Guest
|
Posted: Tue Mar 21, 2006 5:03 pm Post subject: Re: Using StringList for CSV file |
|
|
You might want to take a look at TntLXCsvUtils.pas from my LX collection:
http://www.tntware.com/delphicontrols/lx/
Take a look at "ExportDataSetToCsvStrings()" to see how I dump a TDataSet to
a string list (encoded as CSV).
(I realize I'm not answering your question about maximum size/number
limits.)
--Troy |
|
| Back to top |
|
 |
Troy Wolbrink Guest
|
Posted: Tue Mar 21, 2006 5:03 pm Post subject: Re: Using StringList for CSV file |
|
|
Some places use a semicolon for a Comma Seperated Values file. Imagine
that!
I always export CSV files with a comma, but when I import files, I always
check the first row to see if it was delimited with semicolons or commas.
You can't trust the list seperator defined by the current locale, because
the file may have come from somewhere else.
I have a good CSV parser in my LX collection
(http://www.tntware.com/delphicontrols/lx/) in TntLXCsvUtils.pas.
You basically just create a TTntCSVTable, and call LoadFromFile.
--Troy
"Bruce McGee" <bmcgee (AT) glooscap (DOT) com> wrote in message
news:xn0ejzpxu76m128000 (AT) newsgroups (DOT) borland.com...
| Quote: | John Herbster wrote:
My only problems with writing CSV files is figuring out the
internationalization issues with commas, stops, semicolons,
and quotes.
Do CSV files use periods in Europe? :)
If I don't write my own parser to chop up a string's comma separated
values, I use AnsiQuotedStr and AnsiDequotedStr to make sure any white
space or special characters are wrapped and let TStringList's CommaText
do the heavy lifting.
In Delphi 2006 (and maybe 2005?), TStringList has a StrictDelimiter
property. Set this to True and it will only use the specified
delimiter with CommaText instead of also using spaces.
--
Regards,
Bruce McGee
Glooscap Software |
|
|
| Back to top |
|
 |
Chris Morgan Guest
|
Posted: Tue Mar 21, 2006 6:03 pm Post subject: Re: Using StringList for CSV file |
|
|
| Quote: | Do CSV files use periods in Europe? :)
No, but numbers use commas for decimal points
|
CSV is a very poorly-defined format, and is no good
for internationalisation of applications
or trans-national data.
You'd be better off in these cases using an XML schema.
At least XML defines its own decimal separators and
date formats.
CSV files are very difficult to parse if you don't
know the locale of the environment which created them.
Even Microsoft Excel doesn't do this very well.
Also, a TStringList (if I remember correctly) does
not parse unquoted strings correctly (this may be
from a Delphi version a long time ago).
It's just as easy to asseble each line as a string
and write it out to file using WriteLn.
Cheers,
Chris |
|
| Back to top |
|
 |
John Herbster Guest
|
Posted: Tue Mar 21, 2006 7:03 pm Post subject: Re: Using StringList for CSV file |
|
|
"Bruce McGee" <bmcgee (AT) glooscap (DOT) com> wrote
| Quote: | My only problems with writing CSV files is figuring out the
internationalization issues with commas, stops, semicolons,
and quotes.
Do CSV files use periods in Europe?
|
Has anyone tracked down when and how the "ListSeparator"
(Windows' LOCALE_SLIST) is supposed to be used?
--JohnH |
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Tue Mar 21, 2006 7:03 pm Post subject: Re: Using StringList for CSV file |
|
|
Troy Wolbrink wrote:
| Quote: | I have a good CSV parser in my LX collection
(http://www.tntware.com/delphicontrols/lx/) in TntLXCsvUtils.pas.
You basically just create a TTntCSVTable, and call LoadFromFile.
|
I haven't seen this before, but it looks useful. Thanks.
--
Regards,
Bruce McGee
Glooscap Software |
|
| Back to top |
|
 |
Bruce McGee Guest
|
Posted: Tue Mar 21, 2006 7:03 pm Post subject: Re: Using StringList for CSV file |
|
|
Jim Cooper wrote:
| Quote: |
Do CSV files use periods in Europe? :)
No, but numbers use commas for decimal points
|
I know (and in Quebec). Note the smiley. :)
--
Regards,
Bruce McGee
Glooscap Software |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|