In the docs for String.Format there is an alignment component which
allows you to pad the field to a certain number of spaces.
e.g.
FormatFName = String.Format("First Name = |{0,10}|", myFName);
Pads myFName, width of 10 minimum
I am used to printf which allows a '*' to be used to specify a
variable to be used at runtime to specify the width of the column.
e.g.
printf("%*s", iColWidth, myFName);
Pads myFName, width of iColWidth minimum
Am I missing something or did we lose that power in C#? I would hate
to have to build my format string at runtime just to do this. 2 8194 ts******@gmail.com wrote:
In the docs for String.Format there is an alignment component which
allows you to pad the field to a certain number of spaces.
e.g.
FormatFName = String.Format("First Name = |{0,10}|", myFName);
Pads myFName, width of 10 minimum
I am used to printf which allows a '*' to be used to specify a
variable to be used at runtime to specify the width of the column.
e.g.
printf("%*s", iColWidth, myFName);
Pads myFName, width of iColWidth minimum
Am I missing something or did we lose that power in C#? I would hate
to have to build my format string at runtime just to do this.
As far as I know, that's the only way. Ex:
string myFName = "tom";
int iColWidth = 10;
string FormatFName = string.Format(string.Format("First Name =
|{{0,{0}}}|", iColWidth), myFName);
--
Tom Porterfield
On Aug 9, 3:38 pm, Tom Porterfield <tppor...@mvps.orgwrote:
tstep...@gmail.com wrote:
In the docs for String.Format there is an alignment component which
allows you to pad the field to a certain number of spaces.
e.g.
FormatFName = String.Format("First Name = |{0,10}|", myFName);
Pads myFName, width of 10 minimum
I am used to printf which allows a '*' to be used to specify a
variable to be used at runtime to specify the width of the column.
e.g.
printf("%*s", iColWidth, myFName);
Pads myFName, width of iColWidth minimum
Am I missing something or did we lose that power in C#? I would hate
to have to build my format string at runtime just to do this.
As far as I know, that's the only way. Ex:
string myFName = "tom";
int iColWidth = 10;
string FormatFName = string.Format(string.Format("First Name =
|{{0,{0}}}|", iColWidth), myFName);
--
Tom Porterfield
Thanks, that is exactly what I ended up doing - ugly code though. I
am surprised .NET lost functionality however - it would have been easy
to add this. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: blackdevil1979 |
last post by:
Hello,
Is there a way to format the data when it is passed into the Crystal
Report(CR).. for example.. In the original table, a number may be
left aligned, how to change it to right alignment?.....
|
by: Sam |
last post by:
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?...
|
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...
|
by: Doug Bell |
last post by:
Hi
Does anyone know (or point me where I can find) how to set the alignment of
a DataGrid Column Header different to the alignment of the column.
I am trying to show some Right aligned columns...
|
by: Samuel Shulman |
last post by:
Hi
For numeric columns I want to align it to the right
How can I do that?
Samuel
| |
by: Brian Gladman |
last post by:
A lot of low level cryptographic code and some hardware cryptographic
accelerators either fail completely or perform very poorly if their input,
output and/or key storage areas in memory are not...
|
by: Rahul |
last post by:
Friends,
My Problem is related to writing a text file from a database
using .Net. in a particular string format.
I have a dataset with a table, let suppose in this table there are
three fields....
|
by: Rahul |
last post by:
Friends,
My Problem is related to writing a text file from a database
using .Net. in a particular string format.
I have a dataset with a table, let suppose in this table there are
three fields....
|
by: uamusa |
last post by:
I am Dynamically generating a proposal(report) in MS Word. By default the Paragraph Alignment is "Left". For the First 6 Paragraphs I set the Alignment to "Center", and then when attempting to...
|
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,...
|
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,...
| |
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: 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...
|
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...
|
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...
|
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 ...
| |
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...
| |