我想做一个小程序。输入一个词,可以统计一篇文章里面包含这个词有多少个。
这个程序怎么写啊?使用C#写。
那位高手给点建议啊!谢谢

解决方案 »

  1.   

    这个简单,给你个简单的例子
    我在winform中做的,form1中有个richtextbox且访问级别是public,form2是个查找替换form1中的richtextbox的功能,我在此只给你写统计查找到多少个的代码
    在form1中点击查找按钮 Form2 f=new Form2();
    s.Owner=this;
    s.Show();在form2中有个查找的对象的textbox文本框,有个查找按钮,在查找按钮中写 int index=0,count=0;
    private void button1_Click(object sender, System.EventArgs e)
    {
    Form1 f1=(Form1)this.Owner;
    if(this.textBox1.Text.Length>0)
    {
    index=f1.richTextBox1.Text.IndexOf(textBox1.Text,index);
    if(index==-1)
    {
    MessageBox.Show("没有找到相关的内容!");
    index=0;
    }
    else
    {
    f1.richTextBox1.Select(index,this.textBox1.Text.Length);
    index+=this.textBox1.Text.Length;
                        count++;
    f1.Activate();
    }
    }
    else
    {
    MessageBox.Show("请输入查找的对象!");
    }
                MessageBox.Show("一共查找到"+count+"个");
    }
      

  2.   

    哦,写了个小错误,在form1中点击查找按钮里的代码,
                Form2 f=new Form2();
                s.Owner=this;
                s.Show();
    下面的s写错了,应该是f,我也不知道我怎么写成了s
      

  3.   

    最简单的
           string a = "11111111111111111111111";
                MessageBox.Show(a.Split(new string[1]{"11"}, StringSplitOptions.None).Length.ToString());