Dim strCHI As String 'strCHI 为一个汉字 cArea = Asc(strCHI) cArea = cArea + 65536 如果cArea在45217和55359之间就是汉字
下面的函数是本人贴在http://www.csdn.net/expert/topic/181/181622.shtm上,已经通过验证。 判断是否是中文字符的函数如下 Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, ByVal Source As String, ByVal Length As Long) '该函数判断传入字符是否是GBK汉字库中的字符 '如果是则返回True,否则返回False,绝对不会包括全角的标点和特殊符号[A1-AA]等 Private Function IS_GBK_HZ(ByVal sHZ As String) As Boolean Dim aHZ(1) As Byte sHZ = Left(sHZ, 1) If Len(sHZ) > 0 Then CopyMemory aHZ(0), sHZ, 2 IS_GBK_HZ = (((aHZ(0) >= &H81) And (aHZ(0) < &HA1)) Or ((aHZ(0) >= &HAA) And (aHZ(0) < &HFE))) And (aHZ(1) >= &H40) And (aHZ(1) < &HFF) End If End Function
Dim R() as Byte Dim i as Integer Dim TmpStr as String For i = 1 To Len(Text1.Text) TmpStr = Mid(Text1.Text, i, 1) R = StrConv(TmpStr, vbFromUnicode) If UBound(R) < 1 Then MsgBox "英文" Else MsgBox "汉字" End If Next i
cArea = Asc(strCHI)
cArea = cArea + 65536
如果cArea在45217和55359之间就是汉字
判断是否是中文字符的函数如下
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, ByVal Source As String, ByVal Length As Long)
'该函数判断传入字符是否是GBK汉字库中的字符
'如果是则返回True,否则返回False,绝对不会包括全角的标点和特殊符号[A1-AA]等
Private Function IS_GBK_HZ(ByVal sHZ As String) As Boolean
Dim aHZ(1) As Byte
sHZ = Left(sHZ, 1)
If Len(sHZ) > 0 Then
CopyMemory aHZ(0), sHZ, 2
IS_GBK_HZ = (((aHZ(0) >= &H81) And (aHZ(0) < &HA1)) Or ((aHZ(0) >= &HAA) And (aHZ(0) < &HFE))) And (aHZ(1) >= &H40) And (aHZ(1) < &HFF)
End If
End Function
Dim i as Integer
Dim TmpStr as String
For i = 1 To Len(Text1.Text)
TmpStr = Mid(Text1.Text, i, 1)
R = StrConv(TmpStr, vbFromUnicode)
If UBound(R) < 1 Then
MsgBox "英文"
Else
MsgBox "汉字"
End If
Next i