2012-04-02 69 views
1

简单替代密码。简单替代密码

我试图做一个循环构造,将循环通过一个字符串,并在同一时间写入到另一个字符串。遇到空间时,我无法跳过它。有人能帮我解决这个问题吗?

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++; 
} 

回答

2

如果您想跳过空格,那么只需删除else块即可。如果你想保持它,再加入

translate = translate.concat(' '); 

- 我的回答使用您使用的算法相同的模式 - 这是非常低效的。如果你想构建一个字符串,那么请看看StringBuilder类。