Label1.Caption = LenB(StrConv(Text1.Text, vbFromUnicode))
如果使用len函数,则取到的是字符数。例如:
dim str as string
str='中国china1'
len(str)=8
而 LenB(StrConv(str, vbFromUnicode))=10
即汉字为两个字节
如果使用len函数,则取到的是字符数。例如:
dim str as string
str='中国china1'
len(str)=8
而 LenB(StrConv(str, vbFromUnicode))=10
即汉字为两个字节
博客介绍了VB中字符串长度的计算方法。使用Len函数取到的是字符数,而使用LenB(StrConv(str, vbFromUnicode))可得到字节数,如字符串'中国china1',Len函数结果为8,LenB(StrConv)结果为10,汉字占两个字节。
1620

被折叠的 条评论
为什么被折叠?



