我被困在问题的最后,得到一个NumberFormatException。
我想获取一个字符串,例如Wsup,并将其转换ASCII
为结果,'87115117112'。
我已经通过几种不同的方式成功构建了那串数字,但是当我尝试parseInt(string)
使用它时,我得到了例外。我尝试将字符串打印为字符数组以查找隐藏的空格,但我String.trim()
没有运气使用,我很困惑为什么它不被识别为有效整数。
public static int toAscii(String s){
StringBuilder sb = new StringBuilder();
String ascString = null;
long asciiInt;
for (int i = 0; i < s.length(); i++){
sb.append((int)s.charAt(i));
char c = s.charAt(i);
}
ascString = sb.toString();
asciiInt = Integer.parseInt(ascString); // Exception here
return 0;// asciiInt; 0 in place just to run
}
感谢您提供的任何帮助。