📄 gb2u.java
字号:
package com.khan.code;
import java.io.PrintStream;
public class GB2U {
public GB2U() {
}
public static String gb2u(String s) {
try {
String s1 = new String(s.getBytes("8859_1"), "gb2312");
s = "";
for (int i = 0; i < s1.length(); i++) {
String s2 = Integer.toHexString(s1.charAt(i)).toUpperCase();
//System.out.println(s2);
if (s2.length() < 4) {
s2 = "0000".substring(0, 4 - s2.length()) + s2;
}
s = s + "&#x" + s2 + ";";
}
}catch (Exception exception) {
s = s;
}
return s;
}
public static String iso2u(String s) {
try {
char ac[] = s.toCharArray();
s = "";
for (int i = 0; i < ac.length; i++) {
s = s + "&#x" + Integer.toHexString(ac[i]).toUpperCase() + ";";
}
}catch (Exception exception) {
s = s;
}
return s;
}
public static String gb2umms(String s) {
try {
s = new String(s.getBytes("8859_1"), "gb2312");
char ac[] = s.toCharArray();
s = "";
for (int i = 0; i < ac.length; i++) {
s = s + "\\u" + Integer.toHexString(ac[i]).toUpperCase();
}
} catch (Exception exception) {
s = s;
}
return s;
}
public static String gb2mms(String s) {
byte abyte0[] = new byte[s.length() * 2 + 2];
byte abyte1[] = s.getBytes();
abyte0[0] = (byte) Integer.parseInt("FF", 16);
abyte0[1] = (byte) Integer.parseInt("FE", 16);
for (int i = 0; i < s.length() * 2; i++) {
abyte0[i + 2] = abyte1[i];
}
return new String(abyte0);
}
public String iso2umms(String s) {
try {
char ac[] = s.toCharArray();
s = "";
for (int i = 0; i < ac.length; i++) {
s = s + "\\u" + Integer.toHexString(ac[i]).toUpperCase();
}
}
catch (Exception exception) {
s = s;
}
return s;
}
public String byte2hex(byte abyte0[]) {
String s = "";
String s1 = "";
for (int i = 0; i < abyte0.length; i++) {
String s2 = Integer.toHexString(abyte0[i] & 0xff);
if (s2.length() == 1) {
s = s + "0" + s2;
} else {
s = s + s2;
}
}
return s;
}
public String hex2string(String s) {
byte abyte0[] = new byte[s.length() / 2];
for (int i = 0; i < s.length() / 4; i++) {
abyte0[i * 2] = (byte) Integer.parseInt(s.substring(i * 4, i * 4 + 2), 16);
abyte0[i * 2 + 1] = (byte) Integer.parseInt(s.substring(i * 4 + 2, i * 4 + 4), 16);
}
return new String(abyte0);
}
public static void main(String args[]) {
if (args.length != 1) {
System.out.println("java.B2U chinese");
} else {
GB2U gb2u1 = new GB2U();
System.out.println(gb2u1.gb2u(args[0]));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -