Saturday 2 December 2017

C# Program to Find the Frequency of the Word ʺisʺ in a given Sentence


Code:

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;
    }
}


Output:

Enter the String :
Rose is a Flower
1



More C# Programs:



















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...