随机输入一段话,怎样判断输入的是中文还是字母,各有多少个?

解决方案 »

  1.   

    If c > "~" Then 
         MsgBox "汉字" 
        ElseIf IsNumeric(c) Then 
         MsgBox "数字" 
        ElseIf (c >= "A" And c <= "Z") Or (c >= "a" And c <= "z") Then 
         MsgBox "英文" 
        End If 
      

  2.   

    不好意思,我不懂VB哦,哦,我也不知道是不是VB,但我想在VB下面叛断一个是否为汉字很简单,因为VB把一个汉字作为一个字符的,和字母一样,你用如mid()分解出一个汉字(长度为1),然后用lstrlen()(API)函数求一下长度,如果为2就一定为汉字了。
      

  3.   

    //Func::
    void DealChar( char *pChar, int *nEnglishCount, int *nChineseCount )
    {
        int nECount = 0, nCCount = 0;
        for( int i = 0; i < strlen( pChar ); i ++ )
        {
            if( pChar[i] > 128 )
               nCCount ++;
            else
               nECount ++;
        }
        *nEnglishCount = nECount;
        *nChineseCount = nCCount;
    }//Use
    int nC = 0, nE = 0;
    char buf[1024] = "Hello 中国人!";
    DealChar( buf, &nE, &nC );
    // nE = 7, nC = 6
      

  4.   

    转载:
    #include "stdafx.h"
    #include <tchar.h>
    #include "string"
    using namespace std;
    #include "windows.h"int main(int argc, char* argv[])
    {
    char *str="abc中文汉字def";
    char *p=str,*p1;
    unsigned short ch;
    //str2按字遍历字符串
    string str2="";
    while(strcmp(p,"")!=0)
    {
    str2="";
    p1=CharNextExA(936,p,0);
    int i=p1-p;
    if(i==1)
    {
    ch=(unsigned char)*p;
    str2+=*p;
    }else if(i==2)
    {
    ch=(*p)*256+*(p+1);
    str2+=*p;
    str2+=*(p+1);
    }
    p=p1;
    // p是剩下的字符串,ch是一个字的值
    }
    return 0;
    }
      

  5.   

    那段代码是拷的一段VB代码
    char str[]="汉";
    应该str[1]<0吧