vb6.0项目升级到vb.net(LenB(StrConv(str,type)))
上一篇 /
下一篇 2012-06-16 10:22:43
/ 个人分类:技术杂谈--随笔录
在项目由vb6.0升级到vb2005时遇到LenB()函数,在vb2005中此函数不存在,所以找替代的方法的研究,仅供参考如有不正确请指出
系统:windowsxp x86
开发环境:vb6.0 vs2005
vb2005和vb6.0中字符串默认采用的编码方式为uncoide
vb2005中没有替代vbFormUncoide的类型
VB6.0: Dim str as String Dim bytesCount as Integer str="hello" '字母占一个字节,汉字和日文占两个字节 bytesCount=LenB(StrConv(str,vbFormUncoide)) 'StrConv(str,vbFormUncoide)将字符串的编码方式转换为系统缺省码页
结果为:bytesCount=5
VB2005中替代的方法 Dim str as String
Dim bytesCount as Integer
str="hello" bytesCount=System.Text.Encoding.Default.GetByteCount(str) ’字符串的编码方式为系统缺省编码
结果:butesCount=5
|
VB6.0和vb2005:
Len()函数计算字节的方式为字符(英文、汉字、日文)占一个字节
VB6.0:
Dim str as String
Dim bytesCount as Integer
str="hello"
'vbUncoide将字符编码转换为uncoide编码
bytesCount=LenB(StrConv(str,vbUncoide)) 'LenB(str)=10 'uncoide编码每个字符占两个字节
结果为:bytesCount=20
如果将str字符编码改为vbFormUncoide之后再运行上面的程序结果为10 Dim str as String
Dim bytesCount as Integer
str="hello" str=StrConv(str,vbFormUncoide) 'StrConv(str,vbFormUncoide)将字符串的编码方式转换为系统缺省码页 '每个字符占两个字节计算
bytesCount=LenB(StrConv(str,vbUncoide)) 'LenB(str)=10
结果为:bytesCount=10
Dim str as String
Dim bytesCount as Integer
str="hello"
str=StrConv(str,vbFormUncoide)
str=StrConv(str,vbFormUncoide)
bytesCount=LenB(StrConv(str,vbUncoide)) 'LenB(str)=4
结果为:bytesCount=4
|
vb2005:
System.Text.Encoding.Uncoide.GetByteCount(str) '每个字符占两个字节
收藏
举报
TAG: