Reverse Middle X Characters | C # implementation of the above approach ; Function to reverse the middle x characters in a string ; Find the position from where the characters have to be reversed ; Print the first n characters ; Print the middle x characters in reverse ; Print the last n characters ; Drived code
using System ; class GFG { static void reverse ( string str , int x ) { int n = ( str . Length - x ) / 2 ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( str [ i ] ) ; for ( int i = n + x - 1 ; i >= n ; i -- ) Console . Write ( str [ i ] ) ; for ( int i = n + x ; i < str . Length ; i ++ ) Console . Write ( str [ i ] ) ; } public static void Main ( ) { string str = " geeksforgeeks " ; int x = 3 ; reverse ( str , x ) ; } }