By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,245 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,245 IT Pros & Developers. It's quick & easy.

Format String of Numeric Values to Right Alignment

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"Sam" <qd*@datawave.ca> wrote in message
news:ub*************@tk2msftngp13.phx.gbl...
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

Nov 21 '05 #2

P: n/a
Sam
Hi all

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

Regards,

Sam
"Sam" <qd*@datawave.ca> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
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

"Sam" <qd*@datawave.ca> wrote in message
news:ub*************@tk2msftngp13.phx.gbl...
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


Nov 21 '05 #3

P: n/a
Hey Sam,
Suggest you put your research into this thread so anyone in the future can
learn from your hard work.
Nov 21 '05 #4

P: n/a
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("")


"Grant_Aust" <ne*******************@carthew.net> wrote in message
news:ud**************@tk2msftngp13.phx.gbl...
Hey Sam,
Suggest you put your research into this thread so anyone in the future can
learn from your hard work.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.