Hai All,
I am working in asp.net...
I need to format a number in the following manner...
number = 500
After formatting i need the number as string as " 500"
that is 5 spaces before number...
If give the number as 2, then i should get as " 2" i.e 7
spaces before the number..
how can format like this??
Please reply...
Looking forward for the response...
Thanx in advance.....
.NET Framework - Format
You can use the PadLeft method to get the formatting you need:
int i = 100;
string s = i.ToString().PadLeft(8, ' ');
will give you a string 8 characters long, with i right justified, so in
this case there will be five spaces before the number.
*** Sent via Developersdex http://www.developersdex.com ***
string format question .NET Framework Hi, I want to make a dynamically string format padding on a given string but I get ABORT when doing it: string aTest = string.Format("- -{0, 10}- -", "test"); / / this is OK string aTest2 = string.Format("- -{0, -10}- -", "test"); / / this is
Emulating String.Format compile-time functionality .NET Framework 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? C# Discussions FormatException (1) Format (1) Console (1) Visual (1) No it doesn't. This compiles just fine for me
Creating Blank if zero decimal format string .NET Framework How to create format string for decimal data type which shows blank for zero and default format otherwize ? I tried format string "f;f;#" but this shows f for nonzero numbers. Andrus. using System.Windows.Forms; class 1) StrDecimalFormat (1) That's because 'f' isn't a valid character in custom numeric format strings. http: / / msdn.microsoft.com / en-us / library / 0c899ak8.aspx You can use the standard
Alignment and string.Format .NET Framework 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 did we lose that power in C#? I would hate to have to build my format string at runtime just to do this. C# Discussions FormatFName (1) Format (1) IColWidth (1) MyFName
String Format Custom .NET Framework 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. . . . - - Armando Rocha (Portugal) Mobile Developer http: / / www.ifthensoftware.com C# Discussions IFormatProvider (1) Console.WriteLine (1) StringBuilder (1) RegexOptions (1) String.Format (1) Console (1) Regex (1) Replace (1) In this case, I suspect the easiest option