Format String of Numeric Values to Right Alignment

S

Sam

Hi everyone

I have a question regarding string format. If I want to write a set of
numeric values from arrays to a text file with the "right alignment" format
as below, can it be done? Basically, I want to format a number from an array
to a fix length. I want to line up digits of numbers in a column with
respect to their position. For instant, in Col1 which contains all integers
they should align to the right and in Col2 all number should also their
decimal point aligned and also to the right. Do you guys think this can be
done? In C I would use the fprintf function for example fprintf( o3, "%4d
%16.6e\n", i, j)); to write to a text file. Could you please guys give me a
hand?


Regards,

Sam

Col 1 Col2
8 7.000000
100 42.000000
9 8.000000
10 9.000000
11 10.000000
12 11.000000
 
S

Sam

In addition to formatting a string, I also want to add a delimiters (spaces
or tabs whichever the best)between columns. Do you guys think I should
create a variable that holds some spaces or tabs and write to the text file?

Thanks

Sam
 
S

Sam

Hi all

I just figured out how to do it with string format functions. Thanks all for
looking at my questions.

Regards,

Sam
 
G

Grant_Aust

Hey Sam,
Suggest you put your research into this thread so anyone in the future can
learn from your hard work.
 
S

Sam

Hi Grant,

Thanks for your good suggestion. One can easy forget things when trying to
get his/her work done. Below is the simple code that I used to write data in
block format.

Regards,

Sam


Dim sw as StreamWriter
SW.WriteLine("Start data block") 'block header

SW.Write(mPtList.Count.ToString.PadLeft(5))

SW.Write(mNodeList.Count.ToString.PadLeft(10))

SW.Write(mMatList.Count.ToString.PadLeft(10))

SW.Write(gAnlsMode.ToString.PadLeft(10))

'write blank line for next block

SW.WriteLine("")
 

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