/** tounicode.java */
package com.edgewww.util;
import java.io.*;
/**
* 字符串转换成unicode码的类
* @author 栾金奎 jsp@shanghai.com
* @date 2001-03-05
*/
public class tounicode {
/**
* 把字符串转换成unicode码
* @param strtext 待转换的字符串
* @param code 转换前字符串的编码,如"gbk"
* @return 转换后的unicode码字符串
*/
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 ;
}
}
/** 应用举例 */
/** 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 = "这是简体中文"; %>
<br>
<%=lang %>
<br>
<%=g2u.tounicode(lang,"gbk") %>