
正文
vb.net补零 vb format 补0
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
VB.NET中如何使string的011 +1 = string的012
Dim a As String = "011"
Dim b As String = "1"
Dim c As String
c = (CInt(a) + CInt(b)).ToString.PadLeft(3, "0")
Label1.Text = c
-----------
将a,b转换为整型之后计算,再转换为string型,之后可以用PadLeft(3, "0")这个来左补零,3表示限定为三位,后面那个“0”就是限定不足3位补0。
相关问答
Q1: vb.net 字节数组补0
'写入
Dim bytes() As Byte = {34, 23, 43, 43, 55, 3}
Dim items = (From item In bytes Select item.ToString("000")).ToArray()
System.IO.File.WriteAllLines("c:\test.txt", items)
'读取
Dim items2 = System.IO.File.ReadAllLines("c:\test.txt")
Dim bytes2 = (From item In items2 Select Byte.Parse(item)).ToArray()
For Each item In bytes2
Console.WriteLine(item.ToString())
Next
Q2: vb怎么判断变量里的字符个数不够两个自动在前面补0
vb判断变量里vb.net补零的字符个数不够两个自动在前面补0vb.net补零,提供两种常用的方法;
1、根据长度判断;
a = 5 '注意这里a如果定义为数字类型(Integer、long等)vb.net补零,补零后的变量尽量换一个其vb.net补零他变量值vb.net补零,比如b
If Len(a) 2 Then b = "0" a else b=a ‘如果a长度小于2,就前面补零
2、先补零,再取后2位
a=5
b = "0" a
b= Right(b, 2)
vb.net补零的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vb format 补0、vb.net补零的信息别忘了在本站进行查找喔。







