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 ("請輸入你要查找的那個(gè)單詞的句子:");
string str= Console.ReadLine ();
Console.WriteLine ("請輸入你要查找的那個(gè)單詞:");
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();
}
}
}你把題目說具體些,要在哪個(gè)控件上顯示數(shù)據(jù)上面是英文句子,而這里是字符串,到底是個(gè)英文句子(有空格的Look at the ball),還是隨便寫的,如 dfl j;thedfal; thesdjf 這里的the的個(gè)數(shù)哥們,不好意思,今天才看到,但是我發(fā)現(xiàn)你的還是有問題的,如果你輸入的內(nèi)容沒有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 出現(xiàn)的次數(shù)=" + 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 出現(xiàn)的次數(shù)=" + count;
c#實(shí)現(xiàn),統(tǒng)計(jì)一句英文句子中某個(gè)單詞出現(xiàn)的次數(shù).
c#實(shí)現(xiàn),統(tǒng)計(jì)一句英文句子中某個(gè)單詞出現(xiàn)的次數(shù).
其他人氣:640 ℃時(shí)間:2020-05-19 18:57:15
優(yōu)質(zhì)解答
我來回答
類似推薦
- C程序設(shè)計(jì) 統(tǒng)計(jì)一句英文句子單詞個(gè)數(shù)
- perl統(tǒng)計(jì)句子每個(gè)單詞出現(xiàn)次數(shù)
- java代碼題 給出一段英文句子,讓你把句子里的每個(gè)單詞(無縮寫形式) 出現(xiàn)次數(shù)計(jì)算出來!
- 統(tǒng)計(jì)若干行英文中單詞的個(gè)數(shù)和每個(gè)單詞出現(xiàn)的次數(shù).
- 有沒有能統(tǒng)計(jì)一篇英文文章中所有單詞出現(xiàn)次數(shù)的軟件
- 求解一道英語語法題
- class seven is having an English class now.改錯(cuò)
- 我最好的朋友(英語作文)
- 人名迷:1.油煎豆腐(打唐朝一詩人名)
- 口算43+5 先算什么 再算什么
- 1.設(shè)f(x)=asin(πx+A)+bcos(πx+B),其中a,b,A,B為非零常數(shù),若f(2009)=-1,則f(2010)= 2.函數(shù)y=2sin(π/6-2x) x屬于【0,π】的單調(diào)遞增區(qū)間是.
- 1、She (usually) helps me with the English. 2、John (sometimes) watches TV. 對()中的部分提問,
猜你喜歡
- 1船速為4m/s,水速為5m/s,則該船能否垂直過河?
- 2小學(xué)六年級上學(xué)期語文補(bǔ)充習(xí)題第20課怎么寫
- 3管線長100米直徑20厘米油密度是0.830算里面多少油
- 4that從句中能不能用主將從現(xiàn).look,see,watch的區(qū)別
- 5一個(gè)數(shù)擴(kuò)大100倍后得到20,這個(gè)數(shù)是();把0.5縮小到它的十分之一是()
- 6如圖,已知直線AB和CD相交于點(diǎn)O,∠COE是直角,OF平分∠AOE.寫出∠AOC與∠BOD的大小關(guān)系
- 7什么是畫面的張力
- 8一道數(shù)學(xué)題火速!要過程,最好講解!
- 9如何用結(jié)晶法分離乙醇和水?
- 10用不等式表示"a"與4的差是非負(fù)數(shù)
- 11A種飲料每瓶是5分之8升,B種飲料每瓶5分之6升,A種飲料比B種飲料多( )升,多( )百分之幾.
- 12用容量瓶成液體并用玻璃棒引流時(shí),為什么玻璃棒要放在刻度線以下