'请问如何在VB中或者SqlServer中判断一个字符串中是否含有汉字。
'注:字符串中有可能含有日语字符,或者全角模式下的特殊字符(如破折号等),这些都不视为汉字。
出处地址: http://topic.youkuaiyun.com/u/20091125/16/ae9ae50c-d810-4c8e-b83d-bb932b3cc047.html?1381
Private Sub Command1_Click()
Dim strSample As String, i As Long
'strSample = "ffdddd中国vbxxx"
strSample = "ffdddd--vbxxx"
For i = 1 To Len(strSample)
If WhatChar(Mid(strSample, i, 1)) > 0 Then
MsgBox "含有汉字"
Exit For
End If
Next
End Sub
Private Function WhatChar(ByVal vStr As String) As Integer
Dim gbascii As Byte
Dim intChar As Integer
If Asc(vStr) < 0 Then
gbascii = AscB(StrConv(vStr, vbFromUnicode))
If gbascii - 160 > 15 Then
intChar = 1 ' 汉字
Else
intChar = 0 ' 全角符号
End If
Else
intChar = 0 ' 半角英文或数字
End If
WhatChar = intChar
End Function