Board index » cppbuilder » tabular text files

tabular text files


2004-12-09 12:18:24 PM
cppbuilder81
Hello:
I need to read LARGE tabular text file where number of columns & rows are
UNKONOWN.
Each column starts with tagname and then float values.
Col1 Col2 Col3 Col4 Col5 ...
1.1112 2.334 201.1 1219.1 2.15 ...
2.632 2.044 202.3 1319.3 2.35 ...
3.112 2.043 207.1 1214.5 2.52 ...
....
Is LoadFromFile() with StringList is ok (and an efficient way) to use for
this?
How to find number of columns and separate column values from each line?
Thanks,
Sudesh
 
 

Re:tabular text files

Hello:
I need to read LARGE tabular text file where number of columns & rows are
UNKONOWN.
Each column starts with tagname and then float values to be read in an
array.
Col1 Col2 Col3 Col4 Col5 ...
1.1112 2.334 201.1 1219.1 2.15 ...
2.632 2.044 202.3 1319.3 2.35 ...
3.112 2.043 207.1 1214.5 2.52 ...
....
Is LoadFromFile() with StringList is ok (and an efficient way) to use for
this?
How to find number of columns and separate column values from each line?
Thanks,
Sudesh
 

Re:tabular text files

I don't know how large your files are, but TStringList handles
large files fine usually. To work on single lines you can also
use a TStringList. The CommaText or DelimitedText property will
split the line into tokens. Here is an example:
TStringList* AllLines = new TStringList;
AllLines->LoadFromFile("c:/temp/temp.txt");
int RowCount = AllLines->Count;
TStringList* OneLine = new TStringList;
OneLine->CommaText = AllLines->Strings[0];
int ColCount = OneLine->Count;
for(int row = 1; row < RowCount; row++)
{
OneLine->CommaText = AllLines->Strings[row];
for(int col = 0; col < ColCount; col++)
{
ShowMessage(AnsiString().sprintf("Row: %d, Col: %d, Value: %s", row, col, OneLine->Strings[col]));
}
}
delete OneLine;
delete AllLines;
--------------------------------------------------------
"Sudesh" < XXXX@XXXXX.COM >wrote:
Quote
Hello:
I need to read LARGE tabular text file where number of columns & rows are
UNKONOWN.
Each column starts with tagname and then float values to be read in an
array.
Col1 Col2 Col3 Col4 Col5 ...
1.1112 2.334 201.1 1219.1 2.15 ...
2.632 2.044 202.3 1319.3 2.35 ...
3.112 2.043 207.1 1214.5 2.52 ...
....

Is LoadFromFile() with StringList is ok (and an efficient way) to use for
this?

How to find number of columns and separate column values from each line?

Thanks,
Sudesh



 

{smallsort}

Re:tabular text files

Sudesh wrote:
Quote
Hello:
I need to read LARGE tabular text file where number of columns & rows are
UNKONOWN.
Do you mean with tabular that the collums are separated
with a tab character \t ?
Quote
Each column starts with tagname and then float values to be read in an
array.
Col1 Col2 Col3 Col4 Col5 ...
1.1112 2.334 201.1 1219.1 2.15 ...
2.632 2.044 202.3 1319.3 2.35 ...
3.112 2.043 207.1 1214.5 2.52 ...
....

Is LoadFromFile() with StringList is ok (and an efficient way) to use for
this?
Yes.
Quote
How to find number of columns and separate column values from each line?
That depends. Do you use \t ? Wich version of builder do you use ?
Hans.
 

Re:tabular text files

"Sudesh" < XXXX@XXXXX.COM >wrote in message
Quote
I need to read LARGE tabular text file where number of
columns & rows are UNKONOWN. Each column starts
with tagname and then float values.
It would be helpful if you would explain what you want to read the file
into. Do you want to set up an array of the values? Do you want to display
them visual? What exactly do you want to do with the values? There are
several different ways to read files, so it is difficult to tell you which
approach is the best approach for you without knowing what exactly you want
to accomplish.
Gambit
 

Re:tabular text files

Thanks Thorsten.
Files would be about 200+ coluns X 5000+ rows.
AnsiString().sprintf("...
WoW I didnt know it.
One more question: are AnsiString operations slower?
Sudesh
 

Re:tabular text files

Thanks Hans.
Yes i could do it. Thorsten also has given solution.
delimiter is space.
Sudesh
"hans galema" < XXXX@XXXXX.COM >wrote in message
Quote
Sudesh wrote:
>Hello:
>I need to read LARGE tabular text file where number of columns & rows are
>UNKONOWN.

Do you mean with tabular that the collums are separated
with a tab character \t ?

>Each column starts with tagname and then float values to be read in an
>array.
>Col1 Col2 Col3 Col4 Col5 ...
>1.1112 2.334 201.1 1219.1 2.15 ...
>2.632 2.044 202.3 1319.3 2.35 ...
>3.112 2.043 207.1 1214.5 2.52 ...
>....
>
>Is LoadFromFile() with StringList is ok (and an efficient way) to use for
>this?

Yes.

>How to find number of columns and separate column values from each line?

That depends. Do you use \t ? Wich version of builder do you use ?

Hans.
 

Re:tabular text files

Hi Remy:
Yes. I would be reading into arrays and also display the values into
StringGrid.
Thanks.
Sudesh
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Sudesh" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I need to read LARGE tabular text file where number of
>columns & rows are UNKONOWN. Each column starts
>with tagname and then float values.

It would be helpful if you would explain what you want to read the file
into. Do you want to set up an array of the values? Do you want to
display
them visual? What exactly do you want to do with the values? There are
several different ways to read files, so it is difficult to tell you which
approach is the best approach for you without knowing what exactly you
want
to accomplish.


Gambit


 

Re:tabular text files

Hello:
sprintf() is not member of AnsiString!!
Sudesh
"Thorsten Kettner" < XXXX@XXXXX.COM >wrote in message
Quote

for(int col = 0; col < ColCount; col++)
{
ShowMessage(AnsiString().sprintf("Row: %d, Col: %d, Value: %s", row,
col, OneLine->Strings[col]));
}
}

 

Re:tabular text files

Quote
...sprintf() is not member of AnsiString!!
Yes it is. Look in the compiler's include\vcl\dstring.h file.
. Ed
Quote
Sudesh wrote in message
news: XXXX@XXXXX.COM ...

sprintf() is not member of AnsiString!!
 

Re:tabular text files

Sudesh wrote:
Quote
sprintf() is not member of AnsiString!!
Not in all versions of c++builder.
Which version do you use ?
Hans.