我尝试使用此方法将Hex of char字符串转换为String:
public String HexToString(String inputString){
StringBuilder output = new StringBuilder();
for (int i = 0; i < inputString.length(); i+=2) {
String str = inputString.substring(i, i+2);
output.append((char)Integer.parseInt(str, 16));
}
return output.toString();
}
输入是:
“4d442020000000020000000000000008ffffffff000000000000022200 0001b54d514852463220 20000000000000000141 4d5120434d504c4c3333 2020202020d75db05811 51d02000000000000000 00000000000000000000 00000000000000000000 00202020202020202020 20202020202020202020 20202020202020202020 20202020202020202020 20202020202020202043 20202020202020202020 4d504c4c333320202020 20000000000000000000 00000000020202020202 02020202020202020202 02020202020202020202 02020202020200000001 c7765626c6f6 ....”
此方法有效,但我的消息包含奇怪的字符的问题。 转换后,我在标题中收到了这个字符:“μMQHRF2”
问题是如何删除此标题?当消息在Hexa上或转换后我应该这样做吗?以及如何从字符串中删除此字符?
答案 0 :(得分:0)
您可以使用apache commons库。这是链接
https://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Hex.html