Writing text to particular positon in a file

M

Matt

Like to create a txt file from recordset and would like to dump records
to particular columns on txt file.
Like below format
1-4(id) 7-15(name) 20(lastname)

12 BOB SMITH
13 JOHN DOE


stringbuilder did not do the job.
 
A

alantolan

Try string.Format()


string fmt = "{0,-6}{1,-9}{2,-20}";
Trace.WriteLine(string.Format(fmt, 12, "Bob", "Smith"));
Trace.WriteLine(string.Format(fmt, 13, "John", "Doe"));

the value after the comma is the 'column width' and the alignment.

-6 = 6 chars wide, left aligned.

hth,
Alan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top