472,783 Members | 991 Online

Is it possible, using the ToString function, to take an integer and
conver to a string of fiexd width with the leading spaces padded with
zeroes.

e.g. integer 123 converted to a string of length 9 with 6 leading
zeroes i.e. 000000123

integer 98765432 converted to a string of length 9 with 1

Thus, the string is fixed length with leading zeroes to the right.

Cheers

Mark

Jun 25 '07 #1
8 46804
..ToString("000000000");

Marc
Jun 25 '07 #2
On Jun 25, 9:36 am, stainless <Mark.Wingfi...@gmail.comwrote:
Is it possible, using the ToString function, to take an integer and
conver to a string of fiexd width with the leading spaces padded with
zeroes.

e.g. integer 123 converted to a string of length 9 with 6 leading
zeroes i.e. 000000123

integer 98765432 converted to a string of length 9 with 1

Thus, the string is fixed length with leading zeroes to the right.
(You mean leading zeroes to the left, I believe.)

using System;

class Test
{
static void Main()
{
Console.WriteLine (123.ToString("D9"));
Console.WriteLine (98765432.ToString("D9"));
}
}

Jon

Jun 25 '07 #3
that is tidier Jon; I was being dumb ;-p
Jun 25 '07 #4
On 25 Jun, 09:45, "Marc Gravell" <marc.grav...@gmail.comwrote:
.ToString("000000000");

Marc
Thanks,

Cheers

Jun 25 '07 #5
On 25 Jun, 09:51, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Jun 25, 9:36 am, stainless <Mark.Wingfi...@gmail.comwrote:
Is it possible, using the ToString function, to take an integer and
conver to a string of fiexd width with the leading spaces padded with
zeroes.
e.g. integer 123 converted to a string of length 9 with 6 leading
zeroes i.e. 000000123
integer 98765432 converted to a string of length 9 with 1
Thus, the string is fixed length with leading zeroes to the right.

(You mean leading zeroes to the left, I believe.)

using System;

class Test
{
static void Main()
{
Console.WriteLine (123.ToString("D9"));
Console.WriteLine (98765432.ToString("D9"));
}

}

Jon

Cheers
Jun 25 '07 #6
You will have to excuse my inexperience with C# but I cannot get the
ToString("D9") to work when debugging. The message returned is

No overload for method 'ToString' takes '1' arguments

Should I have defined something earlier in my C# to allow the "D9" as
an argument for this method?

Cheers

Mark

Jun 27 '07 #7
On Jun 27, 12:50 pm, stainless <Mark.Wingfi...@gmail.comwrote:
You will have to excuse my inexperience with C# but I cannot get the
ToString("D9") to work when debugging. The message returned is

No overload for method 'ToString' takes '1' arguments

Should I have defined something earlier in my C# to allow the "D9" as
an argument for this method?
What are you calling ToString() on?

If you're writing code in the debugger's immediate window, you may
well find it easier to write a very small test application instead (I
almost always use a console app). That way you're isolated from any
differences between the debugger and "normal" code.

Jon

Jun 27 '07 #8
On 27 Jun, 13:02, "Jon Skeet [C# MVP]" <s...@pobox.comwrote:
On Jun 27, 12:50 pm, stainless <Mark.Wingfi...@gmail.comwrote:
You will have to excuse my inexperience with C# but I cannot get the
ToString("D9") to work when debugging. The message returned is
No overload for method 'ToString' takes '1' arguments
Should I have defined something earlier in my C# to allow the "D9" as
an argument for this method?

What are you calling ToString() on?

If you're writing code in the debugger's immediate window, you may
well find it easier to write a very small test application instead (I
almost always use a console app). That way you're isolated from any
differences between the debugger and "normal" code.

Jon
Many apologies. I sorted it out. I was trying to use ToString with a
non integral type (a value returned in an SQL recordset). Once I
converted this to a type "int", the ToString method allowed for

Cheers

Mark

Jun 27 '07 #9

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