Home All Groups Group Topic Archive Search About

Writing Data In Tabular format in Text File.

Author
17 Oct 2006 7:51 AM
lucky
Hi guys,
i want to write some data in tabular format in text file. i've data in
strings and i want to write like this in file

col1     col2     col3

d1       d1        d1
d2       d2        d2
d3       d3        d3

the problem is, i dont know how can i maintain spaces between the
columns as i dont know which column will have what length of text.

in c++, i think u can do by adding padding to make sure the alignment
remains correctly but i dont know how can i do that in c#.

i would appriciate your help,

thanks
Lucky

Author
17 Oct 2006 8:34 AM
Jeroen
Hi lucky,

Unfortunately, I think you should:

A. Try to find out what the maximum length is of a single cell in all
columns, and add enough whitespace to the other cells while writing to
the text file.

or

B. Start with a single whitespace, and each time you encounter a cell
that would require a previous cell in the column to have more
whitespace, to go back and review all cells in the column (and give
them more whitespaces).

Of course, option B is far more expensive, so you should really try to
know beforehand. I guess this is just a limitation of the constraints
you pose (use txt file and use whitespace).

Btw it feels like txt is perhaps not your best option here? Can't you
save in html and use tables or use a comma-delimited file?

Anyway, hope this helps.

Regards,
Jeroen


lucky schreef:

Show quoteHide quote
> Hi guys,
> i want to write some data in tabular format in text file. i've data in
> strings and i want to write like this in file
>
> col1     col2     col3
>
> d1       d1        d1
> d2       d2        d2
> d3       d3        d3
>
> the problem is, i dont know how can i maintain spaces between the
> columns as i dont know which column will have what length of text.
>
> in c++, i think u can do by adding padding to make sure the alignment
> remains correctly but i dont know how can i do that in c#.
>
> i would appriciate your help,
>
> thanks
> Lucky
Author
17 Oct 2006 10:48 AM
Lucky
hey pal,
thanks for replay. i'm thinking about the first option from the
begining but i wanted to take a chance to ask you people if someone
knows some other way of doing.

the reason why i can't use html or csv file is, i'm write data into the
log file and this file has different kind of data. The data that i need
to write is just a small part of it. that is why i didnt want to write
a long code to find the lenght of data and then format ir. but it
seems. i dont have another way..

thanks anyways,
Lucky

Jeroen wrote:
Show quoteHide quote
> Hi lucky,
>
> Unfortunately, I think you should:
>
> A. Try to find out what the maximum length is of a single cell in all
> columns, and add enough whitespace to the other cells while writing to
> the text file.
>
> or
>
> B. Start with a single whitespace, and each time you encounter a cell
> that would require a previous cell in the column to have more
> whitespace, to go back and review all cells in the column (and give
> them more whitespaces).
>
> Of course, option B is far more expensive, so you should really try to
> know beforehand. I guess this is just a limitation of the constraints
> you pose (use txt file and use whitespace).
>
> Btw it feels like txt is perhaps not your best option here? Can't you
> save in html and use tables or use a comma-delimited file?
>
> Anyway, hope this helps.
>
> Regards,
> Jeroen
>
>
> lucky schreef:
>
> > Hi guys,
> > i want to write some data in tabular format in text file. i've data in
> > strings and i want to write like this in file
> >
> > col1     col2     col3
> >
> > d1       d1        d1
> > d2       d2        d2
> > d3       d3        d3
> >
> > the problem is, i dont know how can i maintain spaces between the
> > columns as i dont know which column will have what length of text.
> >
> > in c++, i think u can do by adding padding to make sure the alignment
> > remains correctly but i dont know how can i do that in c#.
> >
> > i would appriciate your help,
> >
> > thanks
> > Lucky
Author
17 Oct 2006 11:13 AM
C-Services Holland b.v.
Lucky wrote:
Show quoteHide quote
> hey pal,
> thanks for replay. i'm thinking about the first option from the
> begining but i wanted to take a chance to ask you people if someone
> knows some other way of doing.
>
> the reason why i can't use html or csv file is, i'm write data into the
> log file and this file has different kind of data. The data that i need
> to write is just a small part of it. that is why i didnt want to write
> a long code to find the lenght of data and then format ir. but it
> seems. i dont have another way..
>
> thanks anyways,
> Lucky
>
> Jeroen wrote:
>
>>Hi lucky,
>>
>>Unfortunately, I think you should:
>>
>>A. Try to find out what the maximum length is of a single cell in all
>>columns, and add enough whitespace to the other cells while writing to
>>the text file.
>>
>>or
>>
>>B. Start with a single whitespace, and each time you encounter a cell
>>that would require a previous cell in the column to have more
>>whitespace, to go back and review all cells in the column (and give
>>them more whitespaces).
>>
>>Of course, option B is far more expensive, so you should really try to
>>know beforehand. I guess this is just a limitation of the constraints
>>you pose (use txt file and use whitespace).
>>
>>Btw it feels like txt is perhaps not your best option here? Can't you
>>save in html and use tables or use a comma-delimited file?
>>
>>Anyway, hope this helps.
>>
>>Regards,
>>Jeroen
>>
>>
>>lucky schreef:
>>
>>
>>>Hi guys,
>>>i want to write some data in tabular format in text file. i've data in
>>>strings and i want to write like this in file
>>>
>>>col1     col2     col3
>>>
>>>d1       d1        d1
>>>d2       d2        d2
>>>d3       d3        d3
>>>
>>>the problem is, i dont know how can i maintain spaces between the
>>>columns as i dont know which column will have what length of text.
>>>
>>>in c++, i think u can do by adding padding to make sure the alignment
>>>remains correctly but i dont know how can i do that in c#.
>>>
>>>i would appriciate your help,
>>>
>>>thanks
>>>Lucky
>
>

Erm.. put tabs between the columns? (vbTab)


--
Rinze van Huizen
C-Services Holland b.v