您的位置:首页 > 其它

判断一个字符串中是否含有汉字

2009-11-25 16:51 519 查看
'请问如何在VB中或者SqlServer中判断一个字符串中是否含有汉字。
'注:字符串中有可能含有日语字符,或者全角模式下的特殊字符(如破折号等),这些都不视为汉字。

出处地址: http://topic.csdn.net/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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: