/**
* inParam:需要转换的gb2312中文字符 返回:该中文字符对应的UTF-8编码的字符
*/
public static String toUTF(String inPara) {
char temChr;
int ascChr;
int i;
String rtStr = new String("");
if (inPara == null) {
inPara = "";
}
for (i = 0; i < inPara.length(); i++) {
temChr = inPara.charAt(i);
ascChr = temChr + 0;
rtStr = rtStr + "&#x" + Integer.toHexString(ascChr) + ";";
}
return rtStr;
}
java 中文转UTF-8
本文介绍了一个将GB2312编码的中文字符转换为UTF-8编码的方法。通过遍历输入字符串中的每个字符,并将其转换为对应的十六进制形式,最终形成UTF-8编码的字符串。

被折叠的 条评论
为什么被折叠?



