导航

找出含多少个字母和数字

Posted on 2012-12-03 15:29  杨彬Allen  阅读(261)  评论(0)    收藏  举报
找出含多少个字母和数字
    /// <summary>
    /// 找出含多少个字母和数字
    /// </summary>
    public int GetLetterOrDigitCount(string value)
    {
        int count = 0;

        for (int i = 0; i < value.Length; i++)
        {
            var ch = value[i];

            if (ch >= 'a' && ch <= 'z')
            {
                count++;
                continue;
            }
            if (ch >= 'A' && ch <= 'Z')
            {
                count++;
                continue;
            }
            if (char.IsNumber(ch))
            {
                count++;
                continue;
            }
        }
        return count;
    }