WC.EXE项目设计

Wc c = new Wc();//创建对象
            Console.Write("wc.exe");
            string msg = Console.ReadLine();
            string[] newm = msg.Split(new char[] { ' ' });//去掉空格 拆分成几个字符串
            int n = newm.Length;
            string str = newm[n - 1];//记录文件路径
            foreach (string i in newm)
            {
                if (i == "-c")
                {
                    c.Read(str, 1);//字符数目功能
                }
                else if (i == "-w")
                {
                    c.Read(str, 2);//单词数
                }
                else if (i == "-l")
                {
                    c.Read(str, 3);//行数目
                }
//byte[] byData = new byte[10000];//应该注释掉,一开始用的byte类型,后来发现有点问题
        FileStream file = new FileStream(a, FileMode.Open);
        StreamReader sr = new StreamReader(file);//访问文件并读取
        //file.Read(byData, 0, 10000);
        switch (b) 
        {case 1:
                {
                    /*while (byData[i] != '\0')
                    {
                        c++;
                        i++;
                    }*/
                    int Ichar = 0;
                    while ((Ichar = sr.Read()) != -1)    // 不再有可用的字符,则为 -1  
                    {
                        if (Ichar != ' ')
                        {
                            c++;
                        }
                    }
                    Console.WriteLine("字符数为:" + c);
                    file.Close();
                } break;
            case 2:
                {
                    int Ichar = 0; //增加 char[] no = { ' ', '\n', '{', '}', '(', ')', '=',                     '+', '_', '*', '%' };                   
            while ((Ichar = sr.Read()) != -1)    
                    {
                        if (Ichar == ' ' || Ichar == '\n')//这我在想想更准确的判断方法 - -!
                        {                               //  for (int ss = 0; ss < 11; ss++)
                            w++;                        //  {
                        }                              //    if (Ichar ==no[ss])    这个更加                     准确!
                    }
                    Console.WriteLine("单词数为:" + w);
                    file.Close();
                } break;
            case 3:
                {
                    int Ichar = 0;
                    while ((Ichar = sr.Read()) != -1)    
                    {
                        if (sr.ReadLine() != null)
                        {
                            l++;
                        }
                    }
                    Console.WriteLine("行数为:" + l);
                    file.Close();
                } break;
        }

  

转载于:https://www.cnblogs.com/tiansurong/p/7599402.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值