1

我有一个带有味精长度的签名味精:

我同意合同中提到的所有条款和条件。3AACBCB0C8FA6A23C72ACBECDE626AC7CD09C9B514CB47E8263150608E915EC2F64F7A13AA7BFEFC49FF2FDE74C0E1F34B33AA964BD03858D67966199A19D4DA5A57566812694AC1B79835EC8A1893DD5CEA709F5B59CB966C6D068837406AB16C762494BD4C9BC0A66E23B5219932FB2DFC82A62D392C0F3C23C793855AAF6C0078

这里 78 只是消息的长度。我需要借助消息长度从签名消息中提取消息。我在java(netbeans)中使用了以下代码:

int MsgLen = Integer.parseInt(Msg.substring(Msg.length() - 4));
System.out.println("Message length: "+MsgLen);

但我收到这样的错误:

线程“AWT-EventQueue-0”java.lang.NumberFormatException 中的异常:对于输入字符串:“78”

如果有人可以帮助我解决问题,请尽快发布您的答案......

4

1 回答 1

0

Glad you fixed it.

Edit: I was wrong about needing to remove the leading zeros. Integer.parseInt handles this for us. Your original code actually works for your example message. Self contained example:

public class IntegerParseTest {
    public static void main(String[] args) {
        String Msg = "3AACBCB0C8FA6A23C72ACBECDE626AC7CD09C9B514CB47E8263150608E915EC2F64F7A13AA7BFEFC49FF2FDE74C0E1F34B33AA964BD03858D67966199A19D4DA5A57566812694AC1B79835EC8A1893DD5CEA709F5B59CB966C6D068837406AB16C762494BD4C9BC0A66E23B5219932FB2DFC82A62D392C0F3C23C793855AAF6C0078";
        Integer MsgLen = Integer.parseInt(Msg.substring(Msg.length() - 4));
        System.out.println("Message length: "+MsgLen);
    }
}

results in:

Message length: 78

I guess your messages have trailing white space which wasn't obvious in the question. Anyway, glad you fixed it.

于 2012-07-18T20:01:23.650 回答