text: Replace every character of string by character whose ASCII value is K times more than it | C # program to move every character K times ahead in a given string ; Function to move string character ; changed string ; iterate for every characters ; ASCII value ; store the duplicate ; if k - th ahead character exceed ' z ' ; print the new string ; Driver Code ; function call
code: using System ; public class GFG { static void encode ( String s , int k ) { String newS = " " ; for ( int i = 0 ; i < s . Length ; ++ i ) { int val = s [ i ] ; int dup = k ; if ( val + k > 122 ) { k -= ( 122 - val ) ; k = k % 26 ; newS += ( char ) ( 96 + k ) ; } else { newS += ( char ) ( 96 + k ) ; } k = dup ; } Console . Write ( newS ) ; } public static void Main ( ) { String str = " abc " ; int k = 28 ; encode ( str , k ) ; } }