蜜桃av色欲a片精品一区,麻豆aⅴ精品无码一区二区,亚洲人成网站在线播放影院在线,亚洲 素人 字幕 在线 最新

微立頂科技

新聞資訊

創(chuàng)新 服務(wù) 價(jià)值

  C#計(jì)算某個(gè)字符在字符串中出現(xiàn)次數(shù)

發(fā)布日期:2022/11/8 12:09:19      瀏覽量:

一、利用Replace(效率不高)

代碼1:

string test = "good good study day day up";
string r = test.Replace("oo", "");
int num = (test.Length - r.Length)/2;
Console.WriteLine(num);

test = "good good study day day up";
r = test.Replace("o", "");
num = (test.Length - r.Length);
Console.WriteLine(num);

二、利用Split(效率最低)

test = "good good study day day up";

int i = test.Split(’d’).Length - 1;

代碼3:

test = "good good study day day up";
int a = test.Split(new string[] { "oo" }, StringSplitOptions.None).Length - 1;

三、利用循環(huán)(效率高)

int c2 = 0;

for (int i = 0; i < test .Length; i++)

{

     if (test [i] == ’a’)

     {

                    c2++;

      }

}

四、利用正則表達(dá)式

Regex rege = new Regex("o", RegexOptions.Compiled);

int count = rege.Matches(test).Count;

五、高效查找字符串出現(xiàn)次數(shù)

string str = "fecvcsdwfchkeov[page]ove283673ewekl[page]fsdh5d37op"; //被查的字符串
int count = 0; //計(jì)數(shù)器
string search = "[page]"; //要查的字符串
for (int i = 0; i < str.Length - search.Length; i++)
{
    if (str.Substring(i, search.Length) == search)
    {
      count++;
     }
}

六、IndexOf、While查找

string text = "今天下雪了嗎,明天不會(huì)下雪了吧,什么時(shí)候才不下雪啊,我要去上學(xué)??!";
string keyWord = "下雪";
int index = 0;
int count = 0;
while ((index = text.IndexOf(keyWord,index)) != -1)
{
count++;
Console.WriteLine("第{0}次;索引是{1}", count, index);
index = index + keyWord.Length;
}
Console.WriteLine("下雪出現(xiàn)的總次數(shù):{0}", count);

七、foreach

int count;
string str="abcbabcbabbcabbabcccc";
foreach(char s in str)
{
  if(s=="a")
  {
     count++;
  }
}
console.write(count.tostring());



  業(yè)務(wù)實(shí)施流程

需求調(diào)研 →

團(tuán)隊(duì)組建和動(dòng)員 →

數(shù)據(jù)初始化 →

調(diào)試完善 →

解決方案和選型 →

硬件網(wǎng)絡(luò)部署 →

系統(tǒng)部署試運(yùn)行 →

系統(tǒng)正式上線 →

合作協(xié)議

系統(tǒng)開發(fā)/整合

制作文檔和員工培訓(xùn)

售后服務(wù)

馬上咨詢: 如果您有業(yè)務(wù)方面的問題或者需求,歡迎您咨詢!我們帶來的不僅僅是技術(shù),還有行業(yè)經(jīng)驗(yàn)積累。
QQ: 39764417/308460098     Phone: 13 9800 1 9844 / 135 6887 9550     聯(lián)系人:石先生/雷先生