I got the following :
01.05.03
I need to convert that to 1.5.3
The problem is I cannot only trim the 0 because if I got :
01.05.10
I need to convert that to 1.5.10
So, what's the better way to solve that problem ? Regex ? If so, any regex example doing that ?
Use the TrimStart() method and set the 0 to remove it.
In C#, Remove() method is a String Method. It is used for removing all the characters from the specified position of a string. If the length is not specified, then it will remove all the characters after specified position.
To remove the first character of a string, we can use the String. Remove() method by passing the 0,1 as arguments. Note: In C# strings are the sequence of characters that can be accessed by using its character index, where the first character index is 0 and the last character index is string.
The lstrip() method to remove leading zeros This method will remove the string given as the argument from the string in operation. When used, it automatically removes leading zeros ( only ) from the string. Note that this works for numbers and all characters accepted as a string.
Expanding on the answer of @FrustratedWithFormsDesigner:
string Strip0s(string s)
{
return string.Join<int>(".", from x in s.Split('.') select int.Parse(x));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With