Created
February 9, 2017 09:23
-
-
Save Chen-tao/a8332dad69871a643cf7a4e2891e1987 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author tadchen | |
* @version 2017年2月9日 | |
* @description TODO | |
*/ | |
public class OctKanji { | |
public static void main(String[] args) throws Exception { | |
String str = URLEncoder.encode("大家好。", "UTF-8"); | |
System.out.println(str); | |
String[] s = str.substring(1).split("%"); | |
StringBuffer s8 = new StringBuffer(); | |
for (int i = 0; i < s.length; i++) { | |
s8.append("\\" + Integer.toOctalString(Integer.valueOf(s[i], 16))); | |
} | |
System.out.println(s8.toString()); | |
String x = s8.toString(); | |
String[] xList = x.split("\\\\"); | |
StringBuffer kanji = new StringBuffer(); | |
System.out.println(xList.length); | |
for (String string : xList) { | |
if (StringUtils.isNotBlank(string)) { | |
System.out.println(string + " " + Integer.toHexString(Integer.valueOf(string,8))); | |
kanji.append("%"); | |
kanji.append(Integer.toHexString(Integer.valueOf(string,8))); | |
} | |
} | |
System.out.println(kanji.toString()); | |
System.out.println(URLDecoder.decode(kanji.toString(), "UTF-8")); | |
} | |
public static String oct2kanji(String x) throws UnsupportedEncodingException{ | |
String[] xList = x.split("\\\\"); | |
StringBuffer kanji = new StringBuffer(); | |
System.out.println(xList.length); | |
for (String string : xList) { | |
if (StringUtils.isNotBlank(string)) { | |
System.out.println(string + " " + Integer.toHexString(Integer.valueOf(string,8))); | |
kanji.append("%"); | |
kanji.append(Integer.toHexString(Integer.valueOf(string,8))); | |
} | |
} | |
System.out.println(kanji.toString()); | |
String kanjiString = URLDecoder.decode(kanji.toString(), "UTF-8"); | |
System.out.println(kanjiString); | |
return kanjiString; | |
} | |
public static String kanji2oct(String kanji) throws UnsupportedEncodingException{ | |
String str = URLEncoder.encode(kanji, "UTF-8"); | |
System.out.println(str); | |
String[] s = str.substring(1).split("%"); | |
StringBuffer s8 = new StringBuffer(); | |
for (int i = 0; i < s.length; i++) { | |
s8.append("\\" + Integer.toOctalString(Integer.valueOf(s[i], 16))); | |
} | |
System.out.println(s8.toString()); | |
return s8.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment