如何使用C#删除前导零 [英] How to remove leading zeros using C#

查看:187
本文介绍了如何使用C#删除前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#删除字符串中的前导零?

How to remove leading zeros in strings using C#?

例如,在以下数字中,我想删除所有前导零。

For example in the following numbers, I would like to remove all the leading zeros.

0001234
0000001234
00001234


推荐答案

这实际上取决于NVARCHAR的持续时间,因为上述几种方法(尤其是通过IntXX进行转换的方法)不适用于:

It really depends on how long the NVARCHAR is, as a few of the above (especially the ones that convert through IntXX) methods will not work for:

String s = "005780327584329067506780657065786378061754654532164953264952469215462934562914562194562149516249516294563219437859043758430587066748932647329814687194673219673294677438907385032758065763278963247982360675680570678407806473296472036454612945621946";

类似这样的事情

String s ="0000058757843950000120465875468465874567456745674000004000".TrimStart(new Char[] { '0' } );
// s = "58757843950000120465875468465874567456745674000004000"

这篇关于如何使用C#删除前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆