text: Left Rotation and Right Rotation of a String | C # program for Left Rotation and Right Rotation of a String ; function that rotates s towards left by d ; function that rotates s towards right by d ; Driver code
code: using System ; class GFG { static String leftrotate ( String str , int d ) { String ans = str . Substring ( d , str . Length - d ) + str . Substring ( 0 , d ) ; return ans ; } static String rightrotate ( String str , int d ) { return leftrotate ( str , str . Length - d ) ; } public static void Main ( String [ ] args ) { String str1 = " GeeksforGeeks " ; Console . WriteLine ( leftrotate ( str1 , 2 ) ) ; String str2 = " GeeksforGeeks " ; Console . WriteLine ( rightrotate ( str2 , 2 ) ) ; } }