Find the count of substrings in alphabetic order | C # to find the number of substrings in alphabetical order ; Function to find number of substrings ; Iterate over string length ; if any two chars are in alphabetic order ; find next char not in order ; return the result ; Driver function
using System ; public class Solution { public static int findSubstringCount ( string str ) { int result = 0 ; int n = str . Length ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( ( char ) ( str [ i ] + 1 ) == str [ i + 1 ] ) { result ++ ; while ( ( char ) ( str [ i ] + 1 ) == str [ i + 1 ] ) { i ++ ; } } } return result ; } public static void Main ( string [ ] args ) { string str = " alphabet " ; Console . WriteLine ( findSubstringCount ( str ) ) ; } }