text: Number of substrings that start with " geeks " and end with " for " | C # implementation of the approach ; Function to return the count of required substrings ; For every index of the string ; If the substring starting at the current index is " geeks " ; If the substring is " for " ; Driver code
code: using System ; public class GFG { static int countSubStr ( String s , int n ) { int c1 = 0 , c2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n - 5 && " geeks " . Equals ( s . Substring ( i , 5 ) ) ) { c1 ++ ; } if ( i < n - 3 && " for " . Equals ( s . Substring ( i , 3 ) ) ) { c2 = c2 + c1 ; } } return c2 ; } public static void Main ( String [ ] args ) { String s = " geeksforgeeksisforgeeks " ; int n = s . Length ; Console . WriteLine ( countSubStr ( s , n ) ) ; } }