编写一个Windows应用程序,该程序功能为:从本机读取一个文本文件(文件中不包含中文字符和符号),统计文件中字符的个数,“,”个数,“.”个数。并把文件中小写英文字母转化为大写,大写字母转化为小写字母。急!!!!!!

解决方案 »

  1.   

    string Temp = string.Empty;
    string UpperTemp = string.Empty;
    string LowerTemp = string.Empty;
    Temp = "aBc";
    UpperTemp = Temp.ToUpper();
    LowerTemp = Temp.ToLower();
      

  2.   

    我想得到的是"AbC",就是小写字符转化为大写,大写转化为小写!都是string型的!
      

  3.   


                using (StreamReader sr = new StreamReader("文本路径"))
                {
                    string text = sr.ReadToEnd();
                    int commaCount = 0;
                    int letterCount = 0;
                    int dotCount = 0;
                    StringBuilder sb = new StringBuilder();
                    foreach (char c in text)
                    {
                        if (char.IsLetter(c))
                            letterCount++;
                        if (c == ',')
                            commaCount++;
                        if (c == '.')
                            dotCount++;
                        if (c >= 'a' && c <= 'z')
                            sb.Append(char.ToUpper(c));
                        else if (c >= 'A' && c <= 'Z')
                            sb.Append(char.ToLower(c));
                        else
                            sb.Append(c);
                    }
                    Console.WriteLine("字母个数为{0}", letterCount);
                    Console.WriteLine(",个数为{0}", commaCount);
                    Console.WriteLine(".个数为{0}", dotCount);
                    Console.WriteLine("改变大小写后内容为:");
                    Console.WriteLine(sb.ToString());
                }
      

  4.   

    StringBuilder是在哪个using里面呀?谢谢楼上的!^_^
      

  5.   


    using System;
    using System.Text;
    using System.IO;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                StreamReader sr = new StreamReader(args[0]);
                string text = sr.ReadToEnd();
                string outText = "";
                int total = 0;
                int dohao = 0;
                int juhao = 0;
                foreach (char c in text)
                {
                    char newc = c;
                    switch (c)
                    {
                        case ',': dohao++; break;
                        case '.': juhao++; break;
                        default:
                            if (Char.IsLower(c))
                            {
                                newc = Char.ToUpper(c);
                            }
                            else if (Char.IsUpper(c))
                            {
                                newc = Char.ToLower(c);
                            }
                            break;
                    
                    }
                    total++;
                    outText += newc;
                }            Console.WriteLine("总字数:{0}", total);
                Console.WriteLine(" ,个数:{0}", dohao);
                Console.WriteLine(" .个数:{0}", juhao);
                Console.WriteLine("转换后:{0}", outText);
                Console.ReadLine();
            }
        }
    }
      

  6.   

    int count0 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^.]", "").Length;//.个数
    int count1 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^,]", "").Length;//,的个数
    int count2 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^a-z]", "").Length;//小写字母的个数
    int count3 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^A-Z]", "").Length;//大写字母的字数
    int count4 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^A-Za-z]", "").Length;//字母的个数
    int count5 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^\d]", "").Length;//数字的个数
    ..................................