convert string to hex and back with different encoding

主宰稳场 提交于 2019-12-12 03:14:52

问题


I want to convert a String value to hex and then back to it's ascii value. when I'm converting it to the hex value i'm doing it with the charset - cp424.

this is what i'm trying to do:

String str = "abcאבג";               
String hexString = Hex.encodeHexString(str.getBytes("cp424")); 
//some action         
String original_value = Hex.decodeHex(hexString.toCharArray()).toString();

My problem is beacuse i'm using cp424 when converting to hex I need when converting back to get it back to the defult charset. I tried this convertion in many ways but didn't get the correct value.

how can this be done? how can i get back the original value from the hex value??

Thank's In Advance.


回答1:


Create original_value using the String(byte[] bytes, String charsetName) constructor:

String original_value = new String(Hex.decodeHex(hexString.toCharArray()), "cp424");


来源:https://stackoverflow.com/questions/10293502/convert-string-to-hex-and-back-with-different-encoding

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!