Hi,
Did anyone have a sample of function that can set a prefix on every number?
Let's say, format current number length is 10. My number is 28790. When i pass this 28790 to above function, it will return a 0000028790. When i pass 2897690 to above function, it will return a 0002897690.
Please help me.
Jan MontanoPosted Apr 13, 2009, 2:59 AM
{
int input = 5555;
string output = PrefixWithCharacter(input, '0', 10);
Console.WriteLine(output); // outputs 0000005555
Console.ReadLine();
}
static string PrefixWithCharacter(int input, char value, int length)
{
StringBuilder format = new StringBuilder();
for (int i = 1; i <= length; i++ )
{
format.Append(value);
}
return input.ToString(format.ToString());
}
Aleksandar IlioskiPosted Apr 11, 2009, 9:29 PM
2870 and 0028790 are the same thing.. and probably it can't be done as integer... i don't know...
but this maybe help you
textBox1.Text= textBox1.Text.PadLeft(10,
'0');the return value is String not number.. and if you try to convert to number it become 2870 again...
but it maybe is what you are looking for