How to remove leading zeros in strings using C#?
For example in the following numbers, I would like to remove all the leading zeros.
0001234 00000012
Regex rx = new Regex(@"^0+(\d+)$"); rx.Replace("0001234", @"$1"); // => "1234" rx.Replace("0001234000", @"$1"); // => "1234000" rx.Replace("000", @"$1"); // => "0" (TrimStart will convert this to "") // usage var outString = rx.Replace(inputString, @"$1");