ASCII错误消息,找不到符号

时间:2018-08-14 18:54:01

标签: java string ascii

private void btnTranslateActionPerformed(java.awt.event.ActionEvent evt){
        字符串strSecretMessage;

    strSecretMessage = this.txtSecretMessage.getText();

    for (int i=0; i < (strSecretMessage.length()-1); i++){
        lblACSII.setText(i+" "+ strSecretMessage.charCodeAt(i));
    }
}   

出现charCodeAt错误,提示找不到符号。

1 个答案:

答案 0 :(得分:1)

lblACSII.setText(i+" "+ (int)strSecretMessage.charAt(i));

charAt()获取字符并将其强制转换为int将提供ascii值

String temp = "";
for (int i=0; i < (strSecretMessage.length()-1); i++){
     temp += i+" "+ strSecretMessage.charCodeAt(i) + " ";
 }
lblACSII.setText(temp);