Count of substrings of a Binary string containing only 1 s | C # implementation to find count of substring containing only ones ; Function to find the total number of substring having only ones ; Driver code
using System ; class GFG { static int countOfSubstringWithOnlyOnes ( string s ) { int res = 0 , count = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { count = s [ i ] == '1' ? count + 1 : 0 ; res = ( res + count ) ; } return res ; } public static void Main ( string [ ] args ) { string s = "0110111" ; Console . Write ( countOfSubstringWithOnlyOnes ( s ) ) ; } }