Writing text to particular positon in a file

  • Thread starter Thread starter Matt
  • Start date Start date
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.
 
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.
 
Back
Top