hsz
hsz

Reputation: 152216

How to remove all zeros from string's beginning?

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";

Upvotes: 38

Views: 41485

Answers (3)

Nick Craver
Nick Craver

Reputation: 630419

You can use .TrimStart() like this:

s.TrimStart('0')

Example:

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

Upvotes: 20

Oleks
Oleks

Reputation: 32323

by using

s.TrimStart("0".ToCharArray())

Upvotes: 2

SwDevMan81
SwDevMan81

Reputation: 49978

I would use TrimStart

string no_start_zeros = s.TrimStart('0');

Upvotes: 89

Related Questions