Extract substrings between any pair of delimiters | Function to print strings present between any pair of delimeters ; Stores the indices of ; If opening delimeter is encountered ; If closing delimeter is encountered ; Extract the position of opening delimeter ; Length of substring ; Extract the substring ; Driver Code
function printSubsInDelimeters ( str ) { let dels = [ ] ; for ( let i = 0 ; i < str . length ; i ++ ) { if ( str [ i ] == ' ' ) { dels . push ( i ) ; } else if ( ( str [ i ] == ' ' ) && ( dels . length > 0 ) ) { let pos = dels [ dels . length - 1 ] ; dels . pop ( ) ; let len = i - 1 - pos ; let ans ; if ( pos < len ) { ans = str . substring ( pos + 1 , len + 1 ) ; } else { ans = str . substring ( pos + 1 , len + pos + 1 ) ; } document . write ( ans + " " ) ; } } } let str = " " ; printSubsInDelimeters ( str ) ;