c#,find,frequency,of,the,word,in,sentence

Ron 8/15/2016 0

This Code Shows How to Find the Frequency of the Word ʺisʺ in a given Sentence

C#
 using System;
class program
{
    public static void Main()
    {
        string s1;
        Console.WriteLine("Enter the String : ");
        s1 = Console.ReadLine();
        Console.WriteLine(counting.CountStringOccurrences(s1, "is"));
        Console.ReadLine();
    }
}
public static class counting
{
    public static int CountStringOccurrences(string text, string pattern)
    {
        int count = 0;
        int i = 0;
        while ((i = text.IndexOf(pattern, i)) != -1)
        {
            i  = pattern.Length;
            count  ;
        }
        return count;
    }
} 

/*
Here is the output of the C# Program: Enter the String : Rose is a Flower 1

*/

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments