汉字与unicode字符互相转换处理乱码
来源:互联网 发布:pc端软件开发 编辑:程序博客网 时间:2024/05/17 07:34
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<div id="div1">汉字与unicode字符转换</div>
<textarea id="uc" style="width:300px;height:150px;border:1px buttonface solid;"></textarea>
<br/>
<textarea id="txtboxA" name="txtboxA" style="width:300px;height:150px;border:1px buttonface solid;"></textarea>
<input type="button" value="Change Code To Unicode" onclick="CCTU(txtboxA.value,0);">
<br/>
<script language="javascript">
//unicode to chinese
var s = "中";
var s = s.substr(2);//去掉&#
document.write(String.fromCharCode(parseInt(s,10)));//从Unicode字符值中返回一个字符串
a = "沈阳a,b,c."
b = a.replace(/&#x/gi,"");//去掉&#
b= b.split(";")//分割字符串
for(i = 0;i<b.length-1;i++){
document.write(String.fromCharCode(parseInt(b[i],16)));//从Unicode字符值中返回一个字符串
}
//chinese to unicode
function CCTU(str,htmlct){//writed by dh20156
if(htmlct==null) htmlct = false;
var rega = /^[/u4E00-/u9FA5]*$/;
var regb = /([/uFF00-/uFF80])/;
var regc = /。/;
var regd = //r/;
var newstr = new Array();
var nid = 0;
for(var i=0;i<str.length;i++){
var ts = str.charAt(i);
if(rega.test(ts) || regb.test(ts)){
newstr[nid++] = "&#"+ts.charCodeAt(0)+";";//从指定位置上字符返回Unicode编码
}else if(regc.test(ts)){
newstr[nid++] = ".";
}else if(regd.test(ts) && htmlct){
newstr[nid++] = "<br/>";
}else{
newstr[nid++] = ts;
}
}
document.getElementById("div1").innerHTML = newstr.join('');
document.getElementById("uc").value = newstr.join('');
}
</script>
</body>
</html>
- 汉字与unicode字符互相转换处理乱码
- 汉字与unicode码的互相转换
- .net unicode汉字互相转换
- [收集]ANSI字符与Unicode字符的互相转换
- 汉字与 Unicode 转换
- 字符转换:ANSI,UNICODE互相转换
- UTF-8与Unicode字符的相互转换 与 16进制Unicode转换汉字 重用代码
- UTF-8与Unicode字符的相互转换 与 16进制Unicode转换汉字
- unicode 字符表 ultraedit在汉字乱码
- Unicode与汉字的转换
- .Net(C#)汉字和Unicode编码互相转换
- js 中文汉字、Unicode、ASCII互相转换函数代码
- 汉字简体与繁体互相转换
- C#字串与Unicode互相转换方法
- C#字符串与unicode互相转换
- C#字符串与unicode互相转换
- C#字符串与unicode互相转换
- 字符串与Unicode编码互相转换
- MB1A 追踪
- 逆转中文字符串-->逆转字符串
- 如何选择数据采集卡
- php中获得当前url的方法
- [转帖]Getting Started With POSIX Threads(台湾同胞翻译的)
- 汉字与unicode字符互相转换处理乱码
- WinDriver
- 什么是DoS攻击
- 自定义XML配置文件的操作类
- 我的八个重要选择(摘录)
- 中国有史以来最缠绵词章大盘点
- 17种家常菜竟是健康杀手
- 帮你排除心灵寂寞的九大妙法
- Geometry Shader In Cg2.0 and GLSL 120