获得中文个数

2016-02-09 10:38:58  访问(1358) 赞(0) 踩(0)


    /// <summary>
    /// 获得中文个数
    /// </summary>
    /// <param name="str">
    /// <returns></returns>
    public int GetCn(string str)
    {
        if (str == null || str.Length == 0)
            return 0;

        ASCIIEncoding ascii = new ASCIIEncoding();

        int tempLen = 0;

        byte[] s = ascii.GetBytes(str);

        int iLen = s.Length;

        for (int i = 0; i < iLen; i++)
        {
            if ((int)s[i] == 63)
            {
                ++tempLen;
            }
        }

        return tempLen;
    }


标签:获得中文个数 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)