I don't really know how to do it with StringBuilder but with the String class, you can replace chars with new ones with this:

String (Java Platform SE 7 )

for(int i = 1; i < encoded.length();...