c#实现,统计一句英文句子中某个单词出现的次数.
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/09/20 08:03:17
c#实现,统计一句英文句子中某个单词出现的次数.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s,s1,s2;
int count = 0;
Console.WriteLine ("请输入你要查找的那个单词的句子:");
string str= Console.ReadLine ();
Console.WriteLine ("请输入你要查找的那个单词:");
string serchword= Console.ReadLine ();
int sbcount = serchword.Count();
for (int i = 0; i < str.Count(); i++)
{
if ( i == 0)
{
s1 = " ";
s2 = str.Substring(i + sbcount ,1);
s = str.Substring(i,sbcount);
if (s1 == " " && s2 == " ")
{
if (s == serchword)
count++;
}
}
if (i + serchword.Count() < str.Count() && i != 0)
{
s1 = str.Substring(i - 1,1);
s2 = str.Substring(i + sbcount-1 ,1);
s = str.Substring(i,sbcount);
if (s1 == " " && s2 == " ")
{
if (s == serchword)
count++;
}
}
if (i + serchword.Count() == str.Count() )
{
s1 = str.Substring(i - 1,1);
s2 = " ";
s = str.Substring(i,sbcount);
if (s1 == " " && s2 == " ")
{
if (s == serchword)
count++;
}
break;
}
}
Console.WriteLine(count );
Console.ReadLine();
}
}
}
再问: 要在window窗体实现,并且要使用indexof()方法,这样的话你知道不
再答: 你把题目说具体些,要在哪个控件上显示数据
再问: 题目是:编写Windows应用程序,在文本框textBox1中输入一个字符串,单击“统计”按钮,在label1中显示输出字符串“the”的出现次数(不区分大小写),使用循环结构、Length属性和IndexOf()方法。
再答: 上面是英文句子,而这里是字符串,到底是个英文句子(有空格的Look at the ball),还是随便写的,如 dfl j;thedfal; thesdjf 这里的the的个数
再问: 我已经写出来啦,不过还是要谢谢你! int[] a = new int[50]; string str = textBox1.Text.ToLower (); int m = 0; for (int i = 0; i < str.Length; i++) { int n = str.IndexOf("the") +3; if (n > i) m++; str = str.Substring(n); } label1.Text = "the 出现的次数=" + m;
再答: 哥们,不好意思,今天才看到,但是我发现你的还是有问题的,如果你输入的内容没有the,就会不对,如ddgga,改成如下: string str = textBox1.Text.ToLower(); int m = 0; for (int i = 0; i < str.Length; i++) { int n = str.IndexOf("the") + 3; if (str.IndexOf("the") == -1) break; if (n > i) m++; str = str.Substring(n); } label1.Text = "the 出现的次数=" + m; 下面是我做的,你可以参考下: int indexnumber = 0; string str = textBox1.Text.ToLower(); int count= 0; for (int i = 0; i < str.Length; i++) { indexnumber = str.IndexOf("the",indexnumber ); if (indexnumber == -1) break; indexnumber++; count++; } label1.Text = "the 出现的次数=" + count;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string s,s1,s2;
int count = 0;
Console.WriteLine ("请输入你要查找的那个单词的句子:");
string str= Console.ReadLine ();
Console.WriteLine ("请输入你要查找的那个单词:");
string serchword= Console.ReadLine ();
int sbcount = serchword.Count();
for (int i = 0; i < str.Count(); i++)
{
if ( i == 0)
{
s1 = " ";
s2 = str.Substring(i + sbcount ,1);
s = str.Substring(i,sbcount);
if (s1 == " " && s2 == " ")
{
if (s == serchword)
count++;
}
}
if (i + serchword.Count() < str.Count() && i != 0)
{
s1 = str.Substring(i - 1,1);
s2 = str.Substring(i + sbcount-1 ,1);
s = str.Substring(i,sbcount);
if (s1 == " " && s2 == " ")
{
if (s == serchword)
count++;
}
}
if (i + serchword.Count() == str.Count() )
{
s1 = str.Substring(i - 1,1);
s2 = " ";
s = str.Substring(i,sbcount);
if (s1 == " " && s2 == " ")
{
if (s == serchword)
count++;
}
break;
}
}
Console.WriteLine(count );
Console.ReadLine();
}
}
}
再问: 要在window窗体实现,并且要使用indexof()方法,这样的话你知道不
再答: 你把题目说具体些,要在哪个控件上显示数据
再问: 题目是:编写Windows应用程序,在文本框textBox1中输入一个字符串,单击“统计”按钮,在label1中显示输出字符串“the”的出现次数(不区分大小写),使用循环结构、Length属性和IndexOf()方法。
再答: 上面是英文句子,而这里是字符串,到底是个英文句子(有空格的Look at the ball),还是随便写的,如 dfl j;thedfal; thesdjf 这里的the的个数
再问: 我已经写出来啦,不过还是要谢谢你! int[] a = new int[50]; string str = textBox1.Text.ToLower (); int m = 0; for (int i = 0; i < str.Length; i++) { int n = str.IndexOf("the") +3; if (n > i) m++; str = str.Substring(n); } label1.Text = "the 出现的次数=" + m;
再答: 哥们,不好意思,今天才看到,但是我发现你的还是有问题的,如果你输入的内容没有the,就会不对,如ddgga,改成如下: string str = textBox1.Text.ToLower(); int m = 0; for (int i = 0; i < str.Length; i++) { int n = str.IndexOf("the") + 3; if (str.IndexOf("the") == -1) break; if (n > i) m++; str = str.Substring(n); } label1.Text = "the 出现的次数=" + m; 下面是我做的,你可以参考下: int indexnumber = 0; string str = textBox1.Text.ToLower(); int count= 0; for (int i = 0; i < str.Length; i++) { indexnumber = str.IndexOf("the",indexnumber ); if (indexnumber == -1) break; indexnumber++; count++; } label1.Text = "the 出现的次数=" + count;
c#实现,统计一句英文句子中某个单词出现的次数.
C#中怎样统计数组中一个一维数组中每个元素出现的次数?
从键盘输入一句英文句子,输出出现次数最多的单词及出现的次数,要求标点符号不能算在单词长度中.Java
EXCEL表格中一列数据统计出这一列数据中某个数字出现的总次数,怎么实现?
如何统计一个字符串中出现某个字母的次数
能否统计WORD文档中某个词组出现的次数?
Excel中如何统计某个数出现的次数
做一个C#程序;列出文本中的每个单词和每个单词出现的次数.以及每个单词在句子中出现的次数.
统计若干行英文中单词的个数和每个单词出现的次数.
有没有能统计一篇英文文章中所有单词出现次数的软件
C语言:统计一篇英文文章中所要查询单词出现的次数以及出现的位置
c++怎么实现在一句话中统计某个单词出现的次数.