Open In App
Related Articles

C# Program to Estimate the Frequency of the Word “is” in a Sentence

Improve Article
Save Article
Like Article

Given a string as input, we need to write a program in C# to count the frequency of the word “is” in the string. The task of the program is to count the number of the occurrence of the given word  “is” in the string and print the number of occurrences of “is”. 


Input : string = “The most simple way to prepare for interview is to practice on best computer science portal that is GeeksforGeeks”

Output : Occurrences of “is” = 2 Time

Input : string = “is this is the way to talk to your sister? I don’t know what that is”

Output : Occurrences of “is” = 3 Time

Explanation: The “is” has also occurred in the word “sister” and “this” but we are looking for the word “is” to occur separately. Hence only 3 time.

Using Iterative Methods     


  1. Split the string by spaces
  2. Store all the words in an array of strings.
  3. Now run a loop at 0 to the length of the array of string and check if our string is equal to the word “is”.
  4. If the condition is true increment the count else do not increment it.



// C# program to count the number
// of occurrence of a "is" in
// the given string
using System;
class GFG{
static int countOccurrencesOfIs(string str)
    // Split the string by spaces
    string[] a = str.Split(' ');
    string word = "is";
    // Search for "is" in string
    int count = 0;
    for(int i = 0; i < a.Length; i++)
        // If "is" found increase count
        if (word.Equals(a[i]))
    return count;
// Driver code
public static void Main()
    string str = "is this is the way to talk to your "
                 "sister? I don't know what that is";



Time Complexity: O(n) where n is the length of the string.

Last Updated : 18 Oct, 2021
Like Article
Save Article
Similar Reads
Related Tutorials