Find the number of occurrences of a character upto preceding position | C # program to find the number of occurrences of a character at position P upto p - 1 ; Function to find the number of occurrences of a character at position P upto p - 1 ; Return the required count ; Driver code ; Function call
using System ; class GFG { static int Occurrence ( String s , int position ) { int count = 0 ; for ( int i = 0 ; i < position - 1 ; i ++ ) if ( s [ i ] == s [ position - 1 ] ) count ++ ; return count ; } public static void Main ( String [ ] args ) { String s = " ababababab " ; int p = 9 ; Console . WriteLine ( Occurrence ( s , p ) ) ; } }