Number of substrings of a string | JavaScript program to count number of substrings of a string ; Driver code
function countNonEmptySubstr ( str ) { let n = str . length ; return n * ( n + 1 ) / 2 ; } let s = " " ; document . write ( countNonEmptySubstr ( s ) ) ;