0

Swap Adjacent letters in a word

Ex:LONDON ->OLDNNO

24th Mar 2019, 10:44 AM
mahesh n
mahesh n - avatar
2 Respuestas
+ 1
try this: StringBuilder builder = new StringBuilder(); string s = "LONDON"; for (int i = 1; i < s.Length; i += 2) { builder.Append(s[i]); builder.Append(s[i - 1]); } if (s.Length % 2 == 1) builder.Append(s.Last()); // if the string has an odd number of characters we add the last character (which was not swapped) Console.Write(builder.ToString());
24th Mar 2019, 2:23 PM
gambler
0
Thank you very much .. it's working ....
27th Mar 2019, 3:34 PM
mahesh n
mahesh n - avatar