我如何找到数量的“是"?出现在字符串“这是我的名字"中使用C# [英] HOW do i find number of "is" present in string "This is my name" using c#

查看:98
本文介绍了我如何找到数量的“是"?出现在字符串“这是我的名字"中使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用c#查找字符串"This is my name"中存在的"is"数量.它存在2次,如何使用C#代码显示它?

HOW do i find number of "is" present in string "This is my name" using c#.its exists 2 times how can i show it by using C# code

推荐答案

类似的东西

something like that

private static int occurencesOf(String Value_, String ToSearchIn_) {
    return new Regex("(" + Value_ + ")+", RegexOptions.CultureInvariant | RegexOptions.Compiled).Matches(ToSearchIn_).Count;
}



糟糕...忘记用法...



oops... forget usage...

string testText = "This is my name";
Console.WriteLine(occurencesOf("is", testText));







and

using System.Text.RegularExpressions



[edit]当我赶时间时,我应该避免提问....它是Match es (ToSearchIn _).Count [/edit]



[edit]and I should avoid question when I''m in a hurry.... it''s Matches(ToSearchIn_).Count[/edit]


请帮助我获取结果


检查此代码,可能会有所帮助.

字符串str =这是我的名字"
int len = str.length;
int count = 0;
for(int i = 0; i< len; i ++)>
{
if(str [i] =="i")
{
if(str [i + 1] =="s")
{
count = count ++;
}
}
}
response.write(count);
check this code, this might be helpful.

string str="this is my name"
int len=str.length;
int count=0;
for(int i=0;i<len;i++)>
{
if(str[i]=="i")
{
if(str[i+1]=="s")
{
count=count++;
}
}
}
response.write(count);


这篇关于我如何找到数量的“是"?出现在字符串“这是我的名字"中使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆