Print all possible strings that can be made by placing spaces | C # program to print permutations of a given string with spaces ; Function recursively prints the strings having space pattern i and j are indices in ' String ▁ ▁ str ' and ' buf [ ] ' respectively ; Either put the character ; Or put a space followed by next character ; Function creates buf [ ] to store individual output string and uses printPatternUtil ( ) to print all permutations ; Buffer to hold the string containing spaces 2 n - 1 characters and 1 string terminator ; Copy the first character as it is , since it will be always at first position ; Driver program
using System ; class GFG { static void printPatternUtil ( string str , char [ ] buf , int i , int j , int n ) { if ( i == n ) { buf [ j ] = ' \0' ; Console . WriteLine ( buf ) ; return ; } buf [ j ] = str [ i ] ; printPatternUtil ( str , buf , i + 1 , j + 1 , n ) ; buf [ j ] = ' ▁ ' ; buf [ j + 1 ] = str [ i ] ; printPatternUtil ( str , buf , i + 1 , j + 2 , n ) ; } static void printPattern ( string str ) { int len = str . Length ; char [ ] buf = new char [ 2 * len ] ; buf [ 0 ] = str [ 0 ] ; printPatternUtil ( str , buf , 1 , 1 , len ) ; } public static void Main ( ) { string str = " ABCD " ; printPattern ( str ) ; } }