import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

public class Test {
    public static void main(String[] args) {
        String hexString = "123 abc [0xea][0xb0][0x80][0xeb][0x82][0x98] [0xeb][0x8b][0xa4][0xeb][0x9d][0xbc]";
        do {
            hexString = hexToString(hexString); // output : 123 abc 가나 다라
        } while (hexString.indexOf("[0x") > -1);
        System.out.println("en : " + hexString);
    }
    
    private static String hexToString(String s) {
        try {
            int idx = s.indexOf("[0x");
            if (idx > -1) {
                String t = s.substring(idx, idx + 18);
                String c = new String(Hex.decodeHex(t.replaceAll("\\[0x", "").replaceAll("\\]", "").toCharArray()));
                s = s.replace(t, c);
            }
        } catch (DecoderException e) {
            throw new RuntimeException(e);
        }

        return s;
    }
}

+ Recent posts