I have lines like this:
var abc = "002"; var def = "023";
How can I easily change the lines so that the leading zeros are reset?
The easiest way:
int.Parse(s).ToString();
All cropping methods do not work for inputs "0000", they return an empty string instead of the correct "0".
Take a look at TrimStart :
numberString = numberString.TrimStart('0');
From MSDN:
The TrimStart method removes all leading characters that are in the trimChars parameter from the current line. The trim operation stops when a character is found that is not in trimChars.
If it is always with int, you can simply parse it:
abc = int.Parse(abc).ToString()
var str = int.Parse(abc).ToString(); should do the job, I think. Convert the number to int, and then just convert it to a string.
var str = int.Parse(abc).ToString();
var abc = "0023"; var zeroless = abc.TrimStart('0');
output: "23"
string some_string = "000045"; string ur_desire = int.Parse(some_string).ToString(); Console.WriteLine(ur_desire);
thix ix is a good answer, I think, because it also works with a negative number.