THis is going to seem very elementary but is there an easy way to remove padding from a string that is LeftPadded with "0"?
I have for example: "4422".PadLeft(8,char.Parse("0"));
Gives me "00004422".
I thought that string.LastIndexof("0",0) would give me 3 but instead it gives me 0. I found out that LastIndexOf starts from the back working its way forward. THis will not work for me if a user enters something like 20.43. Basically I need to remove all the left padded "0"s. Does anyone have an easy way of doing this?Santiago Perez
SantiagoPerez Thursday, September 10, 2009 6:19 PM
Just found an easy fix with a function I've never used:
protectedstring RemovePadding(string value)
{
if (value.StartsWith("0"))
{
char[] charsToTrim = {'0'};
value = value.TrimStart(charsToTrim);
}
return value;
}
Santiago Perez
Marked As Answer bySantiagoPerezThursday, September 10, 2009 6:32 PM
SantiagoPerez Thursday, September 10, 2009 6:32 PM
Just found an easy fix with a function I've never used:
protectedstring RemovePadding(string value)
{
if (value.StartsWith("0"))
{
char[] charsToTrim = {'0'};
value = value.TrimStart(charsToTrim);
}
return value;
}
Santiago Perez
Marked As Answer bySantiagoPerezThursday, September 10, 2009 6:32 PM
SantiagoPerez Thursday, September 10, 2009 6:32 PM