Replace char in a StringBuilder object
using System;
using System.Collections.Generic;
using System.Text;
class Program {
static void Main(string[] args) {
StringBuilder greetingBuilder = new StringBuilder("www.java2s.com");
for (int i = (int)'z'; i >= (int)'a'; i--) {
char old1 = (char)i;
char new1 = (char)(i + 1);
greetingBuilder = greetingBuilder.Replace(old1, new1);
}
for (int i = (int)'Z'; i >= (int)'A'; i--) {
char old1 = (char)i;
char new1 = (char)(i + 1);
greetingBuilder = greetingBuilder.Replace(old1, new1);
}
Console.WriteLine("Encoded:\n" + greetingBuilder.ToString());
}
}
Related examples in the same category