473,800 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using WriteLine

I am writing text out to a text file and I want to LEFT justify the text.

I wave found examples for the following:

// Format a negative integer or floating-point number in various ways.
Console.WriteLi ne("Standard Numeric Format Specifiers");
Console.WriteLi ne(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);

But does an option exist to left justify a string? I remember that c/c++
would.

Thanks,

Jerry
Feb 26 '07 #1
2 2051
MSDN says:

<quote>
Format Item Syntax
Each format item takes the following form.

{index[,alignment][:formatString]}

The matching braces ("{" and "}") are required.

Format Item Components
A format item consists of the following components.

Index Component
The mandatory index component, also called a parameter specifier, is a
number starting from 0 that identifies a corresponding element in the list
of values. That is, the format item whose parameter specifier is 0 formats
the first value in the list, the format item whose parameter specifier is 1
formats the second value in the list, and so on.

Multiple format items can refer to the same element in the list of values by
specifying the same parameter specifier. For example, you can format the
same numeric value in hexadecimal, scientific, and number format by
specifying a source string like this: "{0:X} {0:E} {0:N}".

Each format item can refer to any parameter. For example, if there are three
values, you can format the second, first, and third value by specifying a
source string like this: "{1} {0} {2}". A value that is not referenced by a
format item is ignored. A runtime exception results if a parameter specifier
designates an item outside the bounds of the list of values.

Alignment Component
The optional alignment component is a signed integer indicating the
preferred formatted field width. If the value of alignment is less than the
length of the formatted string, alignment is ignored and the length of the
formatted string is used as the field width. The formatted data in the field
is right-aligned if alignment is positive, and left-aligned if alignment is
negative. If padding is necessary, white space is used. The comma is
required if alignment is specified.

Format String Component
The optional formatString component consists of standard or custom format
specifiers. If formatString is not specified, the general ("G") format
specifier is used. The colon is required if formatString is specified.
</quote>

Of this, the most relevant bit, I think, would be:

"The formatted data in the field is right-aligned if alignment is positive,
and left-aligned if alignment is negative."

MSDN is your friend. Along with Google, of course.
Peter
"Jerry" <jp******@gener al-steel.comwrote in message
news:12******** *****@corp.supe rnews.com...
>I am writing text out to a text file and I want to LEFT justify the text.

I wave found examples for the following:

// Format a negative integer or floating-point number in various ways.
Console.WriteLi ne("Standard Numeric Format Specifiers");
Console.WriteLi ne(
"(C) Currency: . . . . . . . . {0:C}\n" +
"(D) Decimal:. . . . . . . . . {0:D}\n" +
"(E) Scientific: . . . . . . . {1:E}\n" +
"(F) Fixed point:. . . . . . . {1:F}\n" +
"(G) General:. . . . . . . . . {0:G}\n" +
" (default):. . . . . . . . {0} (default = 'G')\n" +
"(N) Number: . . . . . . . . . {0:N}\n" +
"(P) Percent:. . . . . . . . . {1:P}\n" +
"(R) Round-trip: . . . . . . . {1:R}\n" +
"(X) Hexadecimal:. . . . . . . {0:X}\n",
-123, -123.45f);

But does an option exist to left justify a string? I remember that c/c++
would.

Thanks,

Jerry

Feb 26 '07 #2
On Mon, 26 Feb 2007 10:29:28 -0600, "Jerry"
<jp******@gener al-steel.comwrote:
>I am writing text out to a text file and I want to LEFT justify the text.
>But does an option exist to left justify a string? I remember that c/c++
would.

Thanks,

Jerry
The syntax of a format specifier is

{index[,alignment][:formatString]}.

For example:

Console.WriteLi ne("**{0,6}**" , 22);
prints ** 22**

Console.WriteLi ne("**{0,-6}**", 22);
prints **22 **

--
Philip Daniels
Feb 26 '07 #3

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

Similar topics

0
6706
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft Visual Basic .NET version of this article, see 308049. For a Microsoft Visual C++ .NET version of this article, see 310071. For a Microsoft Visual J# .NET version of this article, see 320627. This article refers to the following Microsoft .NET...
7
15508
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using DateDiff in VB.NET which is only available in C# if you don't mind linking in Microsoft.VisualBasic.dll to your C# application. I wanted to avoid this so set about a pure C# solution which uses a combination of TimeSpan in whole days and the...
4
15102
by: Ashok | last post by:
Hello I need to programmatically change the permissions (ACL) on a specific registry key in a .NET app. Is there a way to do this in .NET? Thanks for the help, Ashok
0
1109
by: Glich via DotNetMonster.com | last post by:
#using <mscorlib.dll> #using <System.dll> #include "stdlib.h" #include "stdio.h" using namespace System; using namespace System::Text; using namespace System::IO; using namespace System::Net;
3
6808
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer> </Root> I would like to retreive "\Root\Customer\Name" out of it. Something like:
6
6141
by: =?Utf-8?B?U2FtZWVrc2hh?= | last post by:
Hi, I want to write a simple .net program to open a URL, fill in fields, and click on a button to submit it using .net 1.1 framework. Can someone help in suggesting the libraries I should use? I tried using javascript, however, I am not able to make javascript wait for the page to completely load, before trying to access and fill fields on the page. Hence resorted to .net, but not finding the right library to use.
3
8303
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0 build with these methods, will appear to encrypt and decrypt, but the resulting decrypted file will be corrupted. I tried encrypting a .bmp file and then decrypting, the resulting decrypted file under .NET 2.0 is garbage, the .NET 1.1 build works...
1
2455
by: de4ever | last post by:
HI, i have created a windows service using wmi and c# for mantaining a log of all print jobs in the printing queue.It creates log of only those print jobs which are there when the service started.But i want it to create log of a newly added print job to the print queue when the service is running..can any one help please..my simple code is below.. ManagementObjectSearcher searcher =new ManagementObjectSearcher("SELECT * FROM...
1
2115
by: mary mathews | last post by:
Hi, I'm getting an exception while tried to retrive an outlook contact using asp.net in a console application. The exception is as follows: An unhandled exception of type 'System.NullReferenceException' occurred in ConsoleApplication1.exe,Additional information: Object reference not set to an instance of an object .. Can anybody help me pls.... my code is like this..
65
3929
by: Arjen | last post by:
Hi, Form a performance perspective, is it wise to use the ref statement as much as possible? Thanks! Arjen
0
9690
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, 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...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
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,...
0
10033
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5469
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...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.