Mega Code Archive

 
Categories / C# / Language Basics
 

Loop with letter char as the control variable

using System; using System.Collections.Generic; using System.Text; class Program {     static void Main(string[] args) {         string greetingText = "www.rntsoft.com";         for (int i = (int)'z'; i >= (int)'a'; i--) {             char old1 = (char)i;             char new1 = (char)(i + 1);             greetingText = greetingText.Replace(old1, new1);         }         for (int i = (int)'Z'; i >= (int)'A'; i--) {             char old1 = (char)i;             char new1 = (char)(i + 1);             greetingText = greetingText.Replace(old1, new1);         }         Console.WriteLine("Encoded:\n" + greetingText);     } }