获取utf-8源码(从中文到utf-8)
public static string toutf8string(string s) {
stringbuffer sb = new stringbuffer();
for (int i=0;i<s.length();i++) {
char c = s.charat(i);
if (c >= 0 && c <= 255) {
sb.append("="+c);
} else {
byte[] b;
try {
b = character.tostring(c).getbytes("utf-8");
} catch (exception ex) {
system.out.println(ex);
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0) k += 256;
sb.append("=" + integer.tohexstring(k).
touppercase());
}
}
}
return sb.tostring();
}
闽公网安备 35060202000074号