Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As LongPrivate Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim str As String
str = "中华人民共和国abcdefghijklmnopqrstuvwxyz"
a = Len(str)
b = lstrlen(str) - Len(str)
c = a - b
Debug.Print "字符数:"; a
Debug.Print "双字节字符数:"; b
Debug.Print "单字节字符数:"; c
End Sub
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim str As String
str = "中华人民共和国abcdefghijklmnopqrstuvwxyz"
a = Len(str)
b = lstrlen(str) - Len(str)
c = a - b
Debug.Print "字符数:"; a
Debug.Print "双字节字符数:"; b
Debug.Print "单字节字符数:"; c
End Sub
有VBA可用的
要是你先定义个Byte型数组,全部读到数组中后,再逐一分析,时间可缩短上百倍,这我有经验。试试吧,不过Byte型时的双字节字符处理时要特别注意。
如何用Byte变量处理unicode字符呢?难道要声明一个两倍于字符串长度的数组吗?
TO:ILOVEVB2002(我有权保持沉默!知道也不告诉你。) 你凭什么不告诉我??
刚刷新我就发现了,但我想你应该看得出来,双字节的字符首字节大于127。为了准确,你可以预先验证一下:
Dim xc() As Byte
Private Sub Form_Load()
Dim i As Integer
Open "C:\d.txt" For Binary As 1
ReDim xc(LOF(1)) As Byte
Get #1, , xc
For i = 0 To LOF(1)
Debug.Print xc(i) & " "
Next
Close #1
End Sub