473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

format string

vb.net 2003

i used console.writeline to output to screen.

eg
console.writeline ("test1 : " & vbtab & v_test1)
console.writeline ("test2 : " & vbtab & v_test2)
etc etc

result becomes
test1: <tab> result1
test2: <tab> <tab> results2

Although i used a single vbtab , the results is "mis-aligned" because it
depends on v_test1 and v_test2 strings of characters.

What is the best way to put into console.writeline such that i can
pre-defined all vbtabs for best alighment ?

I prefer results to be like this in tabular format :

test1 : result1
test2: result2
etc etc



Nov 23 '05 #1
4 6942
At face value it would appear that the value stored in v_test2 contains a
leading tab character.

If this is the case then you could remove the tab by trimming the value
before outputting it, thus:

Console.Writeline("test2: " & vbtab & v_test2.Trim)

A tab character, rather than forcing the subsequent output to a specific
column, is interpreted by the display agent (output window, Notepad, etc.)
as a number of spaces.

If the labels are of varying length then you would get something like:

test1: result1
test2long: results2

which might also be undesirable.

If you know, in advance, the maximum length of the labels then you can add
extra formatting features such as:

Console.Writeline("{0,-16}" & vbtab & "{1}", "test1:", v_test1.Trim)
Console.Writeline("{0,-16}" & vbtab & "{1}", "test2long:", v_test2.Trim)

and the output would appear as:

test1: result1
test2long: results2

Check out the String.Format method for more information on formatting
features.

"James" <jk****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
vb.net 2003

i used console.writeline to output to screen.

eg
console.writeline ("test1 : " & vbtab & v_test1)
console.writeline ("test2 : " & vbtab & v_test2)
etc etc

result becomes
test1: <tab> result1
test2: <tab> <tab> results2

Although i used a single vbtab , the results is "mis-aligned" because it
depends on v_test1 and v_test2 strings of characters.

What is the best way to put into console.writeline such that i can
pre-defined all vbtabs for best alighment ?

I prefer results to be like this in tabular format :

test1 : result1
test2: result2
etc etc


Nov 23 '05 #2
James,
As Stephany suggests, use a format string, that contains the proper padding.
When using padding as Stephany shows, I would not use vbTab (as the padding
gives that to you). Normally I move the format itself to a constant,
something like:

Const formatLine As String = "{0,-16} {1}"

Console.Writeline(formatLine, "test1:", v_test1.Trim)
Console.Writeline(formatLine, "test2long:", v_test2.Trim)

For details on the format string see:

http://msdn.microsoft.com/library/de...ttingtypes.asp

http://msdn.microsoft.com/library/de...formatting.asp
Alternatively you can use String.PadLeft & String.PadRight to pad the
"label" to the respective # of spaces.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"James" <jk****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
| vb.net 2003
|
| i used console.writeline to output to screen.
|
| eg
| console.writeline ("test1 : " & vbtab & v_test1)
| console.writeline ("test2 : " & vbtab & v_test2)
| etc etc
|
| result becomes
| test1: <tab> result1
| test2: <tab> <tab> results2
|
| Although i used a single vbtab , the results is "mis-aligned" because it
| depends on v_test1 and v_test2 strings of characters.
|
| What is the best way to put into console.writeline such that i can
| pre-defined all vbtabs for best alighment ?
|
| I prefer results to be like this in tabular format :
|
| test1 : result1
| test2: result2
| etc etc
|
|
|
|
|
|
|
Nov 23 '05 #3
one way is to pad the strings with leading (or trailing) spaces, so that
they are the same length each time.
Nov 23 '05 #4
Hal,
Which is what the PadLeft & PadRight I mentioned do:
Alternatively you can use String.PadLeft & String.PadRight to pad the
"label" to the respective # of spaces.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:HB*******************@bignews1.bellsouth.net. ..
| one way is to pad the strings with leading (or trailing) spaces, so that
| they are the same length each time.
|
|
Nov 25 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: san | last post by:
Hello, all! I have question about String.Format method. There are two variants: public static string Format(string, params object); and public static string Format(IFormatProvider, string, params...
6
by: Stuart McGraw | last post by:
I am looking for a VBA "format" or "template" function, that is, a function that takes a format string and a varying number of arguments, and substitutes the argument values into the format string...
11
by: Grumble | last post by:
Hello, I have the following structure: struct foo { char *format; /* format string to be used with printf() */ int nparm; /* number of %d specifiers in the format string */ /* 0 <= nparm <=...
2
by: Bob | last post by:
I'm having trouble the string.Format() throwing exceptions and I can't figure out what I am doing wrong. Given the following setup code: string str = { "one", "two", "three", "four" }; double...
7
by: Alpha | last post by:
Hi, I'm maintaining C# code and am fairly new with C# programming. I'm looking for codes that's droping the 2nd digit of a nuber printed out and I suspect it's the code below. Can someone tell me...
4
by: David Morris | last post by:
Hi Could somebody please explain what the following line of code means String.Format("{0}\{1}.{2:00}", C:\, myfile.txt, 1 It's actually the first argument that I don't understand. What is...
6
by: Scewbedew | last post by:
Suppose I have the following code: string myFormat = "Line1/nLine 2"; string formattedString = string.Format(myFormat); ....that would produce a 2-line output as expected. But if I load...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
7
by: Rick | last post by:
With String.Format, if I have an incorrect number of args specified for a format string, compile fails. How can I implement similar design-time functionality for my own string functions?
8
by: Armando Rocha | last post by:
Hi, Hi have a string with 16 chars "25DD68EDEB8D5E11" and i want show it in form like this "25DD-68ED-EB8D-5E11", i try String.Format("{0:####-####-####-####}", mystr), but not work, i think...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...

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.