基本的に私がやろうとしているのは、文字列を取り、内部のアルファベットの各文字を置き換えますが、スペースを保持し、それらを「ヌル」文字列に変換しないことです。これが、この質問を開く主な理由です。
以下の関数を使用して文字列「a b」を渡すと、「ALPHA BETA」ではなく「ALPHAnullBETA」が返されます。
現在反復処理されている個々の文字がスペースであるかどうかを確認するすべての可能な方法を試しましたが、何も機能していないようです。これらのシナリオはすべて、通常の文字であるかのように false を返します。
public String charConvert(String s) {
Map<String, String> t = new HashMap<String, String>(); // Associative array
t.put("a", "ALPHA");
t.put("b", "BETA");
t.put("c", "GAMA");
// So on...
StringBuffer sb = new StringBuffer(0);
s = s.toLowerCase(); // This is my full string
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
String st = String.valueOf(c);
if (st.compareTo(" ") == 1) {
// This is the problematic condition
// The script should just append a space in this case, but nothing seems to invoke this scenario
} else {
sb.append(st);
}
}
s = sb.toString();
return s;
}