Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

something like that

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


oops... forget usage...

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


and

C#
using System.Text.RegularExpressions


[edit]and I should avoid question when I'm in a hurry.... it's Matches(ToSearchIn_).Count[/edit]
 
Share this answer
 
v5
Plss help me out getting the result
 
Share this answer
 
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);
 
Share this answer
 
static void Main(string[] args)
{
string string1 = "isisisisisisiissisisisis";

string x = string1;

x = x.Replace("is", "$");// Replace by any character

string[] res = x.Split('$');
Console.WriteLine(res.Length - 1);

}
 
Share this answer
 
hi try this

public int GetNoofIs(string input)
{
int count=0;
string[] chunks = input.Split(' ');
foreach (var item in chunks)
{
if (item.ToLower() == "is")
count++;
}
return count;
}

and use this method on your page as

Lable1.Text="No of is = "+GetNoofIs("this is a new post and this is a good one.").ToString();

Output will be 2.
 
Share this answer
 
Comments
jjjjjjjjjjjssssssssssssaaaaaaaaaa 17-Feb-12 12:13pm    
Thanks For The reply.......

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900