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...

这样就可以了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

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

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

0

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

str = "hello,everybody. " 返回false,位置0。(不含汉字和汉语标点符号) str = "hello,ererybody。 " 返回false,位置16。(最后一个句号是汉语标点符号) 先谢过大家了!

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