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 + "&#x" + 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 + "&#x" + Integer.toHexString(ascInt) + ";";
}
return result;
}
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 + "&#x" + 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 + "&#x" + Integer.toHexString(ascInt) + ";";
}
return result;
}
回复Comments
作者:
{commentrecontent}