如何删除前导零 [英] How to remove leading Zeros

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

问题描述

如何使用C#,除去前导零的nvarchar的数据类型?

例如在下面的数字,我想删除前导零。

  0001234
0000001234
00001234


解决方案

这实际上取决于NVARCHAR有多长,照了几张上面的方法不会为工作(特别是通过INTxx处理转换的)的:

 的String = \"005780327584329067506780657065786378061754654532164953264952469215462934562914562194562149516249516294563219437859043758430587066748932647329814687194673219673294677438907385032758065763278963247982360675680570678407806473296472036454612945621946\";

像这样的

 一个String =0000058757843950000120465875468465874567456745674000004000.TrimStart(新的char [] {0});
// S =58757843950000120465875468465874567456745674000004000

How to remove leading Zeros in the nvarchar datatype using C#?

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

0001234
0000001234
00001234

解决方案

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

Something like this would

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

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

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