|
private static String encodestrans(String strgb) { try { return new String(strgb.getBytes("UTF-8"), "GBK"); } catch (UnsupportedEncodingException ex) { return ""; } } static public String StringToUnicode(String text) { String result = ""; int input; StringReader isr; try { isr = new StringReader(new String(text.getBytes(), "GBK")); } catch (UnsupportedEncodingException e) { return "-1"; } try { while ( (input = isr.read()) != -1) { result = result + "" + Integer.toHexString(input) + ";"; } } catch (IOException e) { return "-2"; } isr.close(); return result; } public static String gb2utf(String inStr) { char temChr; int ascInt; int i; String result = new String(""); if (inStr == null) { inStr = ""; } for (i = 0; i < inStr.length(); i++) { temChr = inStr.charAt(i); ascInt = temChr + 0; System.out.println(ascInt); System.out.println(Integer.toBinaryString(ascInt)); result = result + "" + Integer.toHexString(ascInt) + ";"; } return result; }
|
一共有 11 条评论