Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Removing all the first 0 of a string

Tags:

c#

regex

.net-3.5

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 ?

like image 551
Melursus Avatar asked Jun 02 '10 14:06

Melursus


People also ask

How do you remove leading zeros from a string in C#?

Use the TrimStart() method and set the 0 to remove it.

What does .remove do in C#?

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.

How do you delete the first character in a string C#?

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.

How do you remove .0 from a string in Python?

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.


1 Answers

Expanding on the answer of @FrustratedWithFormsDesigner:

string Strip0s(string s)
{
    return string.Join<int>(".", from x in s.Split('.') select int.Parse(x));
}
like image 88
dtb Avatar answered Sep 28 '22 19:09

dtb