Alternatively Merge two Strings in Java | C # code to alternatively merge two strings ; Function for alternatively merging two strings ; To store the final string ; For every index in the strings ; First choose the ith character of the first string if it exists ; Then choose the ith character of the second string if it exists ; Driver code
using System ; class GFG { static string merge ( string s1 , string s2 ) { string result = " " ; for ( int i = 0 ; i < s1 . Length < s2 . Length ; i ++ ) { if ( i < s1 . Length ) result += s1 [ i ] ; if ( i < s2 . Length ) result += s2 [ i ] ; } return result ; } static void Main ( ) { string s1 = " geeks " ; string s2 = " forgeeks " ; Console . WriteLine ( merge ( s1 , s2 ) ) ; } }