请楼主自己完善下:package des;import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter;/** * @date 2009-3-11 * @author Xing,Xiudong * @Email:xingxiuodng[at]gmail.com * @index:http://blog.csdn.net/xxd851116 */ public class CoderUtils { public static char ascii2Char(int ASCII) { return (char) ASCII; } public static String ascii2String(int[] ASCIIs) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < ASCIIs.length; i++) { sb.append((char) ascii2Char(ASCIIs[i])); } return sb.toString(); } public static void main(String[] args) throws IOException { int[] array= new int[]{22909,22909,23398,20064,65281,22825,22825,21521,19978,65281}; System.out.println(ascii2String(array));
String s = "韩"; String m = s.replace("&#", ""); String n = m.substring(0, m.length()-1); int [] a = new int[]{Integer.parseInt(n)}; System.out.println(ascii2String(a)); }}好好学习!天天向上! 韩
先要搞清楚这个 ASII 编码是如何产生的吧? 逆向应该好做得多。
这个韩雪为什么是ASII. 他是UFO不可以吗?
这个代码有问题,它不支持越过2个字节的汉字,不能用 char 和 charAt 或 new String(char[], charSet); 一般网页中直接写上 Unicode Code Point 是想绕过字符集未确定的问题,这样能在任何环境中正常工作,而且当一个字符集或字体设置不正确时也不会出现怪异现象。比如当 code point 超过2个字节的65536 时也不要奇怪,像康熙字典中很多字都是冷僻字超过2字节表示的,有些父母就是这般奇葩非要给孩子起个这样的名字。 int[] codePoints = new int[16]; for (int i = 0; i < 16; i++) { codePoints[i] = 0x20020 + i; }
String a = new String(codePoints, 0, codePoints.length);
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;/**
* @date 2009-3-11
* @author Xing,Xiudong
* @Email:xingxiuodng[at]gmail.com
* @index:http://blog.csdn.net/xxd851116
*/
public class CoderUtils { public static char ascii2Char(int ASCII) {
return (char) ASCII;
} public static String ascii2String(int[] ASCIIs) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ASCIIs.length; i++) {
sb.append((char) ascii2Char(ASCIIs[i]));
}
return sb.toString();
} public static void main(String[] args) throws IOException {
int[] array= new int[]{22909,22909,23398,20064,65281,22825,22825,21521,19978,65281};
System.out.println(ascii2String(array));
String s = "韩";
String m = s.replace("&#", "");
String n = m.substring(0, m.length()-1);
int [] a = new int[]{Integer.parseInt(n)};
System.out.println(ascii2String(a));
}}好好学习!天天向上!
韩
他是UFO不可以吗?
一般网页中直接写上 Unicode Code Point 是想绕过字符集未确定的问题,这样能在任何环境中正常工作,而且当一个字符集或字体设置不正确时也不会出现怪异现象。比如当 code point 超过2个字节的65536 时也不要奇怪,像康熙字典中很多字都是冷僻字超过2字节表示的,有些父母就是这般奇葩非要给孩子起个这样的名字。
int[] codePoints = new int[16];
for (int i = 0; i < 16; i++)
{
codePoints[i] = 0x20020 + i;
}
String a = new String(codePoints, 0, codePoints.length);
System.out.println("字符串:" + a);
System.out.println("字符串换算成 char[] 存储总长度是 :" + a.length());
System.out.println("codePointAt(7) 索引换算成 charAt 索引 :" + a.offsetByCodePoints(1, 7));
String c = a.substring(a.offsetByCodePoints(1, 7), a.offsetByCodePoints(1, 8));
System.out.println("UTF-8 for " + c + " is " + toString(c.getBytes("UTF-8")) + " ==> "
+ new String(c.getBytes("UTF-8"), "UTF-8"));