Expand the string according to the given conditions | C # implementation of the above approach ; Function to expand and print the given string ; Subtract '0' to convert char to int ; Characters within brackets ; Expanding ; Reset the variables ; Driver code
using System ; class GFG { static void expandString ( string strin ) { string temp = " " ; int j ; for ( int i = 0 ; i < strin . Length ; i ++ ) { if ( strin [ i ] >= 0 ) { int num = strin [ i ] - '0' ; if ( strin [ i + 1 ] == ' ( ' ) { for ( j = i + 1 ; strin [ j ] != ' ) ' ; j ++ ) { if ( ( strin [ j ] >= ' a ' && strin [ j ] <= ' z ' ) || ( strin [ j ] >= ' A ' && strin [ j ] <= ' Z ' ) ) { temp += strin [ j ] ; } } for ( int k = 1 ; k <= num ; k ++ ) { Console . Write ( temp ) ; } num = 0 ; temp = " " ; if ( j < strin . Length ) { i = j ; } } } } } public static void Main ( String [ ] args ) { string strin = "3 ( ab ) 4 ( cd ) " ; expandString ( strin ) ; } }