Function LenTrue(str) Dim StrLen Dim i,l StrLen=0 l=Len(str) For i=1 To l c=asc(mid(str,i,1)) IF c<0 Then c=c+65536 End IF IF c>255 then StrLen=StrLen+2 Else StrLen=StrLen+1 End IF Next LenTrue=StrLen End Function知道怎麼求字符真正長度後求漢字個數就不用我說了吧
dim strTemp as string strTemp="adg我们dafsd的中sdf" debug.print lenb(strconv(strTemp,vbFromUnicode))-len(strTemp)
sorry:dim strTemp as string strTemp="adg我们dafsd的中sdf" debug.print len(strconv(strTemp,vbFromUnicode))-len(strTemp)
Dim total As Long Dim count As Long Dim i As Long count = 0 total = Len(str) For i = 1 To total If Asc(Mid(str, i, 1)) < 0 Then count = count + 1 End If Next LenTrue = count
Dim StrLen
Dim i,l
StrLen=0
l=Len(str)
For i=1 To l
c=asc(mid(str,i,1))
IF c<0 Then c=c+65536 End IF
IF c>255 then
StrLen=StrLen+2
Else
StrLen=StrLen+1
End IF
Next
LenTrue=StrLen
End Function知道怎麼求字符真正長度後求漢字個數就不用我說了吧
strTemp="adg我们dafsd的中sdf"
debug.print lenb(strconv(strTemp,vbFromUnicode))-len(strTemp)
strTemp="adg我们dafsd的中sdf"
debug.print len(strconv(strTemp,vbFromUnicode))-len(strTemp)
lenb(strconv(strTemp,vbFromUnicode))-len(strTemp)
Dim count As Long
Dim i As Long
count = 0
total = Len(str)
For i = 1 To total
If Asc(Mid(str, i, 1)) < 0 Then
count = count + 1
End If
Next
LenTrue = count
http://www.xlmz.net/forum/viewthread.php?tid=2036&sid=Y5k07Bsk