Count subsequence of length three in a given string | C # program to find number of occurrences of a subsequence of length 3 ; Function to find number of occurrences of a subsequence of length three in a string ; variable to store no of occurrences ; loop to find first character ; loop to find 2 nd character ; loop to find 3 rd character ; increment count if subsequence is found ; Driver function
using System ; public class GfG { public static int findOccurrences ( string str1 , string substr1 ) { int counter = 0 ; for ( int i = 0 ; i < str1 . Length ; i ++ ) { if ( str1 [ i ] == substr1 [ 0 ] ) { for ( int j = i + 1 ; j < str1 . Length ; j ++ ) { if ( str1 [ j ] == substr1 [ 1 ] ) { for ( int k = j + 1 ; k < str1 . Length ; k ++ ) { if ( str1 [ k ] == substr1 [ 2 ] ) counter ++ ; } } } } } return counter ; } public static void Main ( ) { string str1 = " GFGFGYSYIOIWIN " ; string substr1 = " GFG " ; Console . WriteLine ( findOccurrences ( str1 , substr1 ) ) ; } }