/UTF字符转换
var UTFTranslate = {
Change:function(pValue){
return pValue.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
},
ReChange:function(pValue){
return (pValue.replace(/&#x/g,'%u').replace(/\\u/g,'%u').replace(/;/g,''));
}
};
//Asc转换
var AscTranslate = {
Change: function(pAscString, pBoxId){
box = document.getElementByIdx_x(pBoxId);
box.innerHTML = '';
for(i = 0; i < pAscString.length; i++)
{
var asc = pAscString.charCodeAt(i);
var str = String.fromCharCode(asc);
box.innerHTML += str + ':' + asc + '<br/>';
}
}
}
java
byte [] b;
String utf8_value;
utf8_value = request.getParameter("NAME");//从HTTP流中取"NAME"的UTF8数据
b = utf8_value.getBytes("8859_1"); //中间用ISO-8859-1过渡
String name = new String(b, "GB2312"); //转换成GB2312字符
这是我做的一个项目程序的一段: