Modify string by rearranging vowels in alphabetical order at their respective indices | C # program for the above approach ; Function to arrange the vowels in sorted order in the string at their respective places ; Store the size of the string ; Stores vowels of string S ; Traverse the string , S and push all the vowels to string vow ; If vow is empty , then print S and return ; Convert vow to char array ; Sort vow in alphabetical order ; Traverse the string , S ; Replace S [ i ] with vow [ j ] iif S [ i ] is a vowel , and increment j by 1 ; Print the string ; Driver Code
using System ; public class GFG { static void sortVowels ( string S ) { int n = S . Length ; string vow = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( S [ i ] == ' a ' S [ i ] == ' e ' S [ i ] == ' i ' S [ i ] == ' o ' S [ i ] == ' u ' ) { vow = vow . Substring ( 0 , vow . Length ) + S [ i ] ; } } if ( vow . Length == 0 ) { Console . Write ( S ) ; return ; } char [ ] tempArray = vow . ToCharArray ( ) ; Array . Sort ( tempArray ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( S [ i ] == ' a ' S [ i ] == ' e ' S [ i ] == ' i ' S [ i ] == ' o ' S [ i ] == ' u ' ) { S = S . Substring ( 0 , i ) + tempArray [ j ++ ] + S . Substring ( i + 1 , n - i - 1 ) ; } } Console . Write ( S ) ; } public static void Main ( string [ ] args ) { string S = " geeksforgeeks " ; sortVowels ( S ) ; } }