Simple Substitution Cipher.
I’m trying to make a looping construct that would loop through a string,and at the same time write it to another string. I’m having trouble making it skip when it encounters a space. Can anybody help me out with this.
String translate = "";//create empty string
int xxx = 0; //initialise counter
while(xxx < text.length()) { //based on the original length of input text
if (text.charAt(xxx) != ' '){ //if no white space do this
translate = translate.concat(Character.toString((s2.charAt(copyS.indexOf(text.charAt(xxx))))));
} else { //if there is white space do this. (I'm unsure how to make it skip?)
}
xxx++;
}
If you want to skip the whitespace, then simply remove the
elseblock. If you want to keep it, then addNote – My answer uses the same pattern that you used for the algorithm – it is terribly inefficient. If you want to build a String, then please have look at the
StringBuilderclass.