views:

250

answers:

4

I have a string which is beginning with zeros:

string s = "000045zxxcC648700";

How can I remove them so that string will look like:

string s = "45zxxcC648700";
A: 

is it always numeric ? why dont you parse it to int or long and then go back to string?

Gabriel Guimarães
Sorry - not a numeric, edited.
hsz
Even if it is, a Parse call is pretty heavy for what's requested.
Task
+26  A: 

I would use TrimStart

string no_start_zeros = s.TrimStart('0');
SwDevMan81
Awesome didn't know that method.
Gabriel Guimarães
+2  A: 

by using

s.TrimStart("0".ToCharArray())
Alex
One operation more. What for? :)
abatishchev
@abatishchev: habitually
Alex
Why use the verbose `"0".ToCharArray()` when `'0'` will also suffice?
Ronald
@Ronald: thx I know about it, but it's automatically
Alex
+11  A: 

You an use .TrimStart() like this:

s.TrimStart('0')

Example:

string s = "000045zxxcC648700";
s = s.TrimStart('0');
//s == "45zxxcC648700"
Nick Craver