473,480 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Format String of Numeric Values to Right Alignment

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
4 6586
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1482
by: kevininstructor | last post by:
The following was copied from a web site for learning formatting. Dim myInt As Integer = 100 Dim FormatPrice As String = String.Format("Price = |{0,10:c }|", myInt) Console.WriteLine(FormatPrice)...
2
5303
by: qazmlp | last post by:
I have got the following strings: 121721234567890 13 1217212345 129 Is it possible to do descending sort for these strings based on their numeric values? After sorting, they need to figure...
3
6495
by: success_ny | last post by:
Does anyone have a code snippet to compare those values so I can sort the array of alpha-numeric values that include both characters and integers in it? I.e., if we have values like 4236 and...
3
28091
by: Ken Durden | last post by:
Is it possible to force positive values to have the + sign prefixed on them? double f1 = 1024.2; double f2 = -1024.2; string.Format( "{0:F}", f1 ); // +1024.2 string.Format( "{0:F}", f2 );...
2
1565
by: MM | last post by:
Hi, I have a param class containg these vars:- string key; // eg: "WN" object value; // eg: 1.2 string format; // eg "F2" and I output these to a StreamWriter using ...
3
3984
by: Steve Weixel | last post by:
I'm having problems getting dates to format the way that I need them to. The problem is that I'm used to the VB6 way of doing things, with which the statement Format(37866, "dd MMM yyyy") would...
7
2022
by: Earl | last post by:
Any known fixes for the wacky right-alignment bug in the WinForms datagrid (VS2003)? I've tried Ken's workaround...
2
4214
by: mdeaver2003 | last post by:
I'm trying to output a double using a precision that varies, governed by the value of a precision variable. In C I can do it like this: double pi = 3.14159; int prec = 4; printf( "%.*f",...
7
13605
by: Andrus | last post by:
How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. ...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7044
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7084
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4779
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
181
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.