/** Tounicode.java * *
Package com.edgewww.util;
Import java.io.*;
/**
* A class that converts a string into a Unicode code
* @author Sukinqui jsp@shanghai.com
* @date 2001-03-05
*/
public class Tounicode {
/**
* Convert string to Unicode code
* @param strText strings to be converted
* @param code for the string before the code conversion, such as "GBK"
* @return converted Unicode code string
*/
public string Tounicode (string strtext,string code) throws unsupportedencodingexception{
char c;
String strret = "";
int INTASC;
String Strhex;
StrText = new String (strtext.getbytes ("8859_1"), code);
for (int i = 0; i < strtext.length (); i++) {
c = Strtext.charat (i);
INTASC = (int) c;
if (intasc>128) {
Strhex = integer.tohexstring (INTASC);
strret = strret + "& #x" + strhex+ ";";
}
else{
strret = strret + C;
}
}
return strret;
}
}
/** Application Examples * *
/** gbk2unicode.jsp * *
<meta http-equiv= "Content-type" content= "text/html; Charset=big5 ">
<jsp:usebean id= "g2u" scope= "session" class= "Com.edgewww.util.ToUnicode"/>
<% String lang = "This is Simplified Chinese"; %>
<br>
<%=lang%>
<br>
<%=g2u.tounicode (lang, "GBK")%>