方法定义出错?????
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;
}
}
}
数字在文章中出现的次数,某个字符串在文章中出现的次数都无法实现,应该是方法定义的逻辑出了问题,但是不会改,求路过的大神帮忙改改。。。