写个循环,对每个char元素判断Ascii码,小于128的是字母,否则,可能是汉字

解决方案 »

  1.   

    也许以下这段代码对你有启发。:)
    '目  的:将汉字字符串的声母提出
    '参  数:汉字字符串
    '返回值:声母字符串
    '---------------------------------------------
    Public Function GetChinesePYCode(ByVal strSource As String) As String    Dim strSerial_s As String
        Dim strSerial_t As String
        Dim StrTmp As String
        Dim j As Integer
        Dim i As Integer
        Dim strHelpChar As String
        
        strSerial_s = "啊芭擦搭蛾发噶哈击喀垃妈拿哦啪期然撒塌挖昔压匝座"
        strSerial_t = "abcdefghjklmnopqrstwxyz"
        
        If Len(strSource) >= 50 Then strSource = Left(strSource, 50)
        
        For i = 1 To Len(strSource)
            strHelpChar = Mid(strSource, i, 1)
            If Len(CheckString(strHelpChar)) = 0 Then
                
                If Asc(strHelpChar) >= Asc(Left(strSerial_s, 1)) And Asc(strHelpChar) <= Asc(Right(strSerial_s, 1)) Then
                    '-------------------------------
                    If Asc(strHelpChar) = Asc(Right(strSerial_s, 1)) Then
                        GetChinesePYCode = GetChinesePYCode & Right(strSerial_t, 1)
                    Else
                        For j = 2 To Len(strSerial_s)
                            StrTmp = Mid(strSerial_s, j, 1)
                            If Asc(strHelpChar) < Asc(StrTmp) Then
                                GetChinesePYCode = GetChinesePYCode & Mid(strSerial_t, j - 1, 1)
                                Exit For
                            End If
                        
                        Next j
                    End If
                    
                    '-------------------------------
                Else
                    GetChinesePYCode = GetChinesePYCode & strHelpChar
                End If
            End If
        Next i
        
    End Function
      

  2.   

    string s = "你好abc欢迎yu好";
     int number = 0;  //the Chinese-charcater's number of string
     for(int i=0;i<s.Length;i++)
     {
      if((s[i]>'a'&&s[i]<'z')||(s[i]>'A'&&s[i]<'Z'))
         {
         }
       else
      {
        number++;
      }
    }//then the number
      

  3.   

    最简单的方法:
    using system.text;
    string aaa;
    aaa="a;lskdjfa;lkj";
    int m=aaa.length;
    int m=Encoding.default.getbytes(aaa.tochararray());
    int x=m-n;
      

  4.   

    string value;
    System.Text.UTF8Encoding un = new System.Text.UTF8Encoding();
      icount = un.GetByteCount(value);
    icount=(icount-value.Length)/2
    我的方法只能处理汉字,测试过没问题