vb.net 2003
i used console.writeli ne to output to screen.
eg
console.writeli ne ("test1 : " & vbtab & v_test1)
console.writeli ne ("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.writeli ne 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 4 6997
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.Writeli ne("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.Writeli ne("{0,-16}" & vbtab & "{1}", "test1:", v_test1.Trim)
Console.Writeli ne("{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******** ********@TK2MSF TNGP09.phx.gbl. .. vb.net 2003
i used console.writeli ne to output to screen.
eg console.writeli ne ("test1 : " & vbtab & v_test1) console.writeli ne ("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.writeli ne 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
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.Writeli ne(formatLine, "test1:", v_test1.Trim)
Console.Writeli ne(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******** ********@TK2MSF TNGP09.phx.gbl. ..
| vb.net 2003
|
| i used console.writeli ne to output to screen.
|
| eg
| console.writeli ne ("test1 : " & vbtab & v_test1)
| console.writeli ne ("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.writeli ne 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
|
|
|
|
|
|
|
one way is to pad the strings with leading (or trailing) spaces, so that
they are the same length each time.
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******@bells outh.net> wrote in message
news:HB******** ***********@big news1.bellsouth .net...
| one way is to pad the strings with leading (or trailing) spaces, so that
| they are the same length each time.
|
| This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
object);
What happens if i will use String.Format("{0} and {1}", "one", "two")
instead of String.Format(System.Globalization.CultureInfo.CurrentCulture,
"{0} and {1}", "one", "two")?
|
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 as specified in the format string. For example
fmt("this is $1 format string. arg2 is $2", "short", 3)
would return the string
"this is short format string. arg2 is 3"
Now, the above is easy to write and I have done so. What I want
is...
|
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 <= 4 */
};
|
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 val = { 1.0, 2.0, 3.0, 4.0 };
string fmt = "{0} {1} {2} {3}";
The following variations of string.Format() will work just fine with strings:
string s1 = String.Format(fmt, str, str, str, str); // works
|
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 where I can look up
explaination on the String.Format, the format string part like "("{0:.#0}".
What's the trailing 0 and what is that "0:" means? I assume the "#" is the
place holder character for th value obtain after the comma in the code.
...
| |
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 the purpose of "{0}\{1}.{2:00}"? I've been using VB .NET for a year now, and have never come across anything like this
Best Regards
David Morris
|
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 that very same format string from an xml file:
....load xmlNode WorkNode...
|
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 string and print it.
but i want to use the String.Format() method if possible to do it.
|
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?
|
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 that
it is because the "mystr" it is already a string.
Anyone can help me?
Sorry my english....
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |