473,383 Members | 1,984 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,383 software developers and data experts.

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.WriteLine("Standard Numeric Format Specifiers");
Console.WriteLine(
"(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 2036
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******@general-steel.comwrote in message
news:12*************@corp.supernews.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.WriteLine("Standard Numeric Format Specifiers");
Console.WriteLine(
"(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******@general-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.WriteLine("**{0,6}**", 22);
prints ** 22**

Console.WriteLine("**{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
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...
7
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...
4
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
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...
3
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>...
6
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?...
3
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...
1
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...
1
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...
65
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.