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

楼上说的对,汉字的ASCII码的值全是负数,可以在TEXT控件的KEYPRESS事件中判断ASCII码是否为负。代码楼上已经给出我就不写啦。

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

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

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。(最后一个句号是汉语标点符号) 先谢过大家了!

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

Private Sub Text_KeyPress(KeyAscii As Integer) If (KeyAscii >=Asc("a") and KeyAscii = Asc("A") and KeyAscii

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 nStr$, dStr$, StrN%, Cyc%, CntN%(3) nStr = Trim(Text1.Text) StrN = Len(nStr) For Cyc = 1 To StrN Select Case Asc(Mid(nStr, Cyc, 1)) Case 65 To 90, 97 To 122 CntN(0) = CntN(0) +...

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