例如:
字符串:"阿伟654564"=text1.text
我要判别在这个字符串中是否含有汉字,怎么个判别,越简单越好。

解决方案 »

  1.   

    在vb中如何区分一个变量值为中文还是英文字母? 
    Dim i%For i = 1 To Len(Text1.Text)
        MsgBox Asc(Mid(Text1.Text, i, 1))
    Next
    'asc值在0-255为标准ascii字符你查查msdn可以找到英文字母的ascii值,当返回的值是5位数,则肯定不是英文字符,但有可能是日韩或其他非英语的语言字符,不知道能判断不是英文字符是不是就够了 
      

  2.   

    Public Function LenMbcs(ByVal vStr As String)
       LenMbcs = LenB(StrConv(vStr, vbFromUnicode))
    End Function这是一个取得字符串真正长度的函数,如果是汉字,长度为2,英文或字母则是1你可以:
    Dim i%,nLen%,s$
    nLen=Len(text1)
    For i=1 to nLen
    s=Mid(text1,i,1)
       If LenMbcs(s)=2 then
        '汉字
       Else
        '非汉字
       End If
    Next i'以上的函数还适用于日文、韩文,因为日文、韩文也是双字节的。
      

  3.   

    绕道了Len(txtPassword.Text) <> LenB(StrConv(txtPassword.Text, vbFromUnicode)) 不相同就代表有
      

  4.   

    下面的方法只能判断是否有标准字符以外的字符.dim str as string
    str=text1.textmsgbox checkchr(str)public function CheckChr(inputstr as string) as boolean
    dim i as long    CheckChr=false    for i=1 to len(inputstr)
            if asc(mid(inputstr,i,1))>127 or asc(mid(inputstr,i,1))<0 then
               CheckChr=true
               exit function
            end if
        next
    end function
      

  5.   

    同意Len(txtPassword.Text) <> LenB(StrConv(txtPassword.Text, vbFromUnicode))