在网上找了一个,可能System中没有包含Character这个类,所以,没注意了。
求各位帮忙看一眼。谢谢。

解决方案 »

  1.   

    很简单 提供思路  用ascii码判断就好
      

  2.   

    你对字符做一个单个截取的循环,判断该字符是否在 ascii码 数字和英文的范围之内,如果是
    则统计+1  最后输出统计变量。
      

  3.   

    string s = "hello csdn, hello 404.";
    var query = from x in s.ToUpper() group x by x >= 'A' && x <= 'Z' ? 0 : (x >= '0' && x <= '9' ? 1 : 2) into g select new { type = g.Key, count = g.Count() };
    Console.WriteLine("字母有{0}个", query.Where(x => x.Type == 0).Single().count);
    Console.WriteLine("数字有{0}个", query.Where(x => x.Type == 1).Single().count);
    Console.WriteLine("其它有{0}个", query.Where(x => x.Type == 2).Single().count);
      

  4.   

    正则 试试
    string test = "abCdef12tf356我们都是7";
                    int count1 = Regex.Matches(test,@"\d").Count;// 数字个数:6
                    int count2 = Regex.Matches(test, @"(?i)[a-z]").Count;//字母个数:8
                    int count3 = Regex.Matches(test, @"[\u4e00-\u9fa5]").Count;//汉字个数:4
      

  5.   


                string str = "另顶戴枯aslkdfjasf345sdfa";            char[] arr = str.ToCharArray();            int number = 0;
                int english = 0;            foreach (char c in arr)
                {
                    int i = c + 0;                if (i > 47 && i < 58)
                        number++;
                    else if ((i > 64 && i < 91) || (i > 96 && i < 123))
                        english++;
                }            Console.WriteLine(string.Format("原字符串:{0}\r\n数字:{1} 个\r\n字母:{2} 个", str, number, english));            Console.Write("\n按任一键结束...");
                Console.ReadKey();
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string s = "hello csdn, hello 404.";
                var query = from x in s.ToUpper() group x by x >= 'A' && x <= 'Z' ? 0 : (x >= '0' && x <= '9' ? 1 : 2) into g select new { type = g.Key, count = g.Count() };
                Console.WriteLine("字母有{0}个.", query.Where(x => x.type == 0).Single().count);
                Console.WriteLine("数字有{0}个.", query.Where(x => x.type == 1).Single().count);
                Console.WriteLine("其它有{0}个.", query.Where(x => x.type == 2).Single().count);
            }
        }
    }字母有14个.
    数字有3个.
    其它有5个.
    Press any key to continue . . .
      

  7.   


      用的一楼方法,结果没有问题  //i1字母数量、i2数字数量、i3其它
                int i1=0, i2=0, i3=0;
                string temp = "abcdefghij852为什么417";
                foreach (char item in temp)
                {
                    int i = (int)item;
                    if (i > 47 && i < 58)
                        i2++;
                    else if ((i > 96 && i < 123) || (i > 64 && i < 91))
                        i1++;
                    else
                        i3++;
                }
                string result = string.Format("字母数量:{0},数字数量:{1},文字数量:{2}",i1,i2,i3);
                Console.WriteLine(result);
                Console.ReadLine();
      

  8.   


    string str = "1ah234b100A";
                Regex regex = new Regex("[0-9]");
                Console.WriteLine(regex.Matches(str).Count);
                Console.WriteLine("-----------------------");
                regex = new Regex("[a-z,A-Z]");
                Console.WriteLine(regex.Matches(str).Count);