jwbf.net
当前位置:首页 >> vB 判断汉字 >>

vB 判断汉字

Private Sub Command1_Click() Dim Sum& Sum = 0 For c = 1 To Len(Text1.Text) Char = Mid(Text1.Text, c, 1) If (AscW(Char) > -40870 And AscW(Char) < -19967) Or (AscW(Char) < 40870 And AscW(Char) > 19967) Then Sum = Sum + 1 End If N...

你可以用mid截取单个字符并用ASCII码判断: n=asc(mid(str1,i,1)) if n>0 and n

这样就可以了Private Sub Command1_Click() Dim i, t For i = 1 To Len(Text1.Text) t = Mid(Text1.Text, i, 1) If Asc(t) < 0 Then ' 在VB中,中文的ASCII值总是负值 MsgBox t, 0, "汉字" End If Next End Sub

用函数Asc(),如果小于0的就是汉字(非Ascii),>0的就是Ascii, 这个函数只取字符串的第一个字符进行计算。 如Asc("A"),结果就是65 Asc("我"),结果是-12590

Private Sub Command1_Click()Dim i As IntegerFor i = 1 To Len(Text1.Text) If Asc(Mid(Text1.Text, i, 1)) < 0 Then MsgBox "只能是英文、数字和符号的组合" Exit Sub End IfNext'....继续其他代码End Sub

Private Sub Command1_Click() Dim Sum& Sum = 0 For c = 1 To Len(Text1.Text) Char = Mid(Text1.Text, c, 1) If (AscW(Char) > -40870 And AscW(Char) < -19967) Or (AscW(Char) < 40870 And AscW(Char) > 19967) Then Sum = Sum + 1 End If N...

要看是什么编码,Unicode编码,一个汉字是2字节,相当于两个Ascii码,如果是UTF-8编码,那么每个汉字是3个字节

Dim num As IntegerDim text As Stringtext = "如何用VB统计汉字个数"For i = 1 To Len(text) If Asc(Mid(text, i, 1)) < 0 Then If AscB(StrConv(Mid(text, i, 1), vbFromUnicode)) - 160 > 15 Then num = num + 1 End IfNext iMsgbox "共有" &...

Private Sub Command1_Click() Dim strSj As String Dim i As Long strSj = "你好,joker" For i = 1 To Len(strSj) If Asc(Mid(strSj, i, 1)) < 0 Then Print i, "汉字" Else Print i, "字母" End If Next End Sub

楼上用的是VB.NET,如果是VB6可以参考下这段代码 这里仅仅对字符串变量(如果是)的第一个字符进行判断,lz您可以添加更复杂的判断 Private Sub Command1_Click()Dim a As Varianta = [被检测变量]Select Case TypeName(a) Case "Integer", "Byt...

网站首页 | 网站地图
All rights reserved Powered by www.jwbf.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com