public class Unicode2ASCII {
public static String toHTML(String unicode) {
String tc = unicode;
String output = "";
char[] ca = tc.toCharArray();
for (int i = 0; i < ca.length; ++i) {
char a = ca[i];
if ((int) a > 255) {
output += "&#" + (int) a + ";";
} else {
output += a;
}
}
return output;
}
public static String toJAVA(String unicode) {
String tc = unicode;
String output = "";
char[] ca = tc.toCharArray();
for (int i = 0; i < ca.length; ++i) {
char a = ca[i];
if ((int) a > 255) {
output += "\\u" + Integer.toHexString((int) a);
} else {
output += a;
}
}
return output;
}
}
|