开发者

How to remove all zeros from string's beginning?

开发者 https://www.devze.com 2022-12-28 21:55 出处:网络
I have a string which is beginning with zeros: string s = \"000045zxxcC648700\"; How can I rem开发者_如何转开发ove them so that string will look like:

I have a string which is beginning with zeros:

string s = "000045zxxcC648700";

How can I rem开发者_如何转开发ove them so that string will look like:

string s = "45zxxcC648700";


I would use TrimStart

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


You can use .TrimStart() like this:

s.TrimStart('0')

Example:

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


by using

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

精彩评论

暂无评论...
验证码 换一张
取 消