标题:方法定义出错?????
取消只看楼主
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
结帖率:100%
已结贴  问题点数:50 回复次数:4 
方法定义出错?????
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int count;
            int count1;
            int count2;
            string Repeat;
            int count3;
            string  count4;
            textualEdit text = new textualEdit();       //初始化

            text.str = Console.ReadLine();  //输入一段字符

            //输入一页文章
            count = text.count(text .str );            
            Console.Write("请输入一串字符");            
            Console.WriteLine(count );

            //文章中出现空格个数
            count1 = text.blankSpace(text .str );
            Console.Write("出现空格个数");
            Console.WriteLine(count1);

            //某个字符串在文章中出现的次数
            Repeat = Console.ReadLine();
            count2 = text.repeat(text.str, Repeat);
            Console.Write("某个字符串在文章中出现的次数");
            Console.WriteLine(count2);

            //数字在文章中出现的次数
            count3 = text.amount(text .str );
            Console.Write("数字在文章中出现的次数");
            Console.WriteLine(count3);

            //删除的某一子串后的字符串
            text .st = Console.ReadLine();
            count4 = text.Dele(text .str ,text .st );
            Console.Write("删除的某一子串后的字符串");
            Console.WriteLine(count4);



        }
    }
    public class textualEdit
    {
       public  string str = " ";   //存储一页文章
       public  string s;           // 统计在文章中要查的重复的字符串
       public  string st;          //  要删除的字符串
        public int count(string str)       //统计文章总字数
        {
            this.str = str;
            int Count=0;
            Count = str.Length;
            return Count;

        }
        public int blankSpace(string str)       //统计在文章中出现空格个数
        {
            int count1 = 0;
            this.str = str;
            char[] cara = str.ToCharArray();
            for (int i = 0; i < cara.Length; i++)
            {
                string number=cara[i].ToString ();
                if (number == " ")
                {
                    count1++;
                }
            }
            return count1;
        }
       public int repeat(string str,string s)       //统计某个字符串在文章中出现的次数
        {
            int count3 =0;
            this.str = str;
            this.s = s;
           
            char[] cara = str.ToCharArray();
           
            for (int i = 0; i < cara.Length; i++)
            {
                    if (s .Equals (cara[i]))
                    {
                        count3++;
                    }
               
            }
            return count3;
            
        }
        public int amount(string str)       //统计在文章中出现数字个数
        {
            int count2 = 0;
            this.str = str;
            char[] cara = str.ToCharArray();
            for (int i = 0; i < cara.Length; i++)
            {
                if (cara[i] >= 0 && cara[i] <= 9)
                {
                    count2++;
                }
            }
            return count2;
        }
        public string Dele(string str, string st)        //文章中要删除的某一子串
        {
            this.str = str;
            this.st = st;
            string Del =str.Replace(st,"");
            return Del;


        }

    }
}
数字在文章中出现的次数,某个字符串在文章中出现的次数都无法实现,应该是方法定义的逻辑出了问题,但是不会改,求路过的大神帮忙改改。。。

搜索更多相关主题的帖子: count 文章 
2013-06-19 23:08
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
得分:0 
回复 3楼 lhb62232397
是啊,public int repeat(string str,string s)       //统计某个字符串在文章中出现的次数
        {
            int count3 =0;
            this.str = str;
            this.s = s;
           
            char[] cara = str.ToCharArray();
           
            for (int i = 0; i < cara.Length; i++)
            {
                    if (s .Equals (cara[i]))
                    {
                        count3++;
                    }
               
            }
            return count3;
            
        }
但是不会改,能帮帮忙吗??

你不勇敢,谁替你坚强。。。
2013-06-20 11:56
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
得分:0 
回复 4楼 QJlin
那该怎么写啊??给点意见喂。。。

你不勇敢,谁替你坚强。。。
2013-06-20 11:57
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
得分:0 
还有,现在发现一个问题就是删除的时候只能删除后面的,前面的或者中间的都删除不了诶。。。

你不勇敢,谁替你坚强。。。
2013-06-20 12:12
黄辉
Rank: 4
等 级:业余侠客
帖 子:106
专家分:255
注 册:2013-4-28
得分:0 
回复 8楼 QJlin
哦哦。。。那我试一下,谢谢了。。。

你不勇敢,谁替你坚强。。。
2013-06-20 12:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415593-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.151516 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved