JavaScript编码转换之gb2312转unicode -- &#X形式
<html>
<head>
<title>gb2312 unicode转换工具</title>
<div align=center>
<center>
<table border=0 cellpadding=0 cellspacing=0 style="border-collapse: collapse" width=600 id=AutoNumber1 height=26>
<tr>
<td width=100% height=26>
<p align=center><font face=黑体 size=5 color=#FF0000>unicode 转换工具</font></p>
<p>使用方法:</p>
<p> 在下面的文本框中输入中文文字,按“转化”,即可将其转化为unicode字符。</p>
<p> 再按“还原”,即可将其还原为简体中文。</td>
</tr>
</table>
</center>
</div>
<p align=center>
<textarea cols=82 rows=10 id=code>
</textarea> </p>
<p align=center>
<input type=button onclick=encode(code,this) value=转化>
<script>
var mode="zhuan";
function encode(obj,btn){
if(mode=="zhuan"){
obj.value=obj.value.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"&#x$2;")});
btn.value="还原";
mode="huan";
}else{
obj.value=unescape(obj.value.replace(/&#x/g,'%u').replace(/;/g,''));
btn.value="转化";
mode="zhuan";
}
}
</script></p>
利用javascript来转换
<style>
BODY {
FONT-SIZE: 9pt; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px;
}
input {
FONT-SIZE: 9pt; height: 13pt;
}
</style>
<script language="JavaScript1.2">
/*
This following code are designed and writen by Windy_sk <seasonx@163.net>
You can use it freely, but u must held all the copyright items!
*/
function Str2Unicode(str){
var arr = new Array();
for(var i=0;i<str.length;i++){
arr[i]="&#" + str.charCodeAt(i) + ";";
}
return(arr.toString().replace(/,/g,""));
}
function Unicode2oStr(str){
var re=/&#[\da-fA-F]{1,5};/ig;
var arr=str.match(re);
if(arr==null)return("");
for(var i=0;i<arr.length;i++){
arr[i]=String.fromCharCode(arr[i].replace(/[&#;]/g,""));
}
return(arr.toString().replace(/,/g,""))
}
function modi_str(){
if(document.all.text.method.checked){
if(document.all.text.decode.value!=""){
document.all.text.encode.value = Str2Unicode(document.all.text.decode.value);
}else{
document.all.text.decode.value = Unicode2oStr(document.all.text.encode.value);
}
}else{
if(document.all.text.encode.value!=""){
document.all.text.decode.value = Unicode2oStr(document.all.text.encode.value);
}else{
document.all.text.encode.value = Str2Unicode(document.all.text.decode.value);
}
}
}
</script>
<title>Unicode</title>
<form name=text>
文本原型:<br>
<textarea name="decode" cols="100" rows="10"></textarea>
<br>
转换代码:<br>
<textarea name="encode" cols="100" rows="10"></textarea>
<br>
<input type="checkbox" name="method" checked> 正向转换
<input type=button onclick="modi_str()" value=" 确 定 ">
<input type=reset value=" 清 空 ">
<input type=button onclick="document.all.text.method.checked?document.all.text.encode.select():document.all.text.decode.select()" value=" 全 选 ">
</form>
JavaScript编码转换之gb2312转unicode -- &#X形式的更多相关文章
- 彻底搞清楚字符编码: ASCII, ISO_8859, GB2312,UCS, Unicode, Utf-8
彻底搞清楚字符编码: ASCII, ISO_8859, GB2312,UCS, Unicode, U 1.ASCII: 0-127(128-255未使用),美国标准 2.IS0-8859-1(lati ...
- AJPFX解析关于编码ansi、GB2312、unicode与utf-8的区别
大家平时遇到乱码问题是否有自己的一套解决方案?这篇文章就是介绍一下常用的编码方式关于编码ansi.GB2312.unicode与utf-8的区别 先做一个小小的试验: 在一个文件夹里,把一个txt文本 ...
- php字符编码转换之gb2312转为utf8(转)
在php中字符编码转换我们一般会用到iconv与mb_convert_encoding进行操作,但是mb_convert_encoding在转换性能上比iconv要差很多哦.string iconv ...
- 编码GBK和GB2312、Unicode、UTF-8
一.编码GBK和GB2312 随着计算机发展,各国已经不满足于单纯用ASCII码: 对于我们来说能在计算机中显示中文字符是至关重要的,所以我们还需要一张关于中文和数字对应的关系表: 一个字节8位二进制 ...
- C#中文和UNICODE编码转换
C#中文和UNICODE编码转换 //中文轉為UNICODE string str = "中文"; string outStr = ""; if (!strin ...
- Linux下将UTF8编码批量转换成GB2312编码的方法
Linux下将UTF8编码批量转换成GB2312编码的方法 在sqlplus中导入UTF8编码的sql脚本就会出现乱码错误,这时就需要将UTF8编码转换成GB2312编码,下面为大家介绍下在Linux ...
- 关于 URL 编码及 JavaScript 编码函数【转载+整理】
原文地址:http://www.ruanyifeng.com/blog/2010/02/url_encoding.html 本文内容 引入 环境 测试 JavaScript 编码函数 引入 URL ...
- 完整的java字符串编码转换代码
package book.String; import java.io.UnsupportedEncodingException; /** *//** * 转换字符串的编码 * @author joe ...
- java字符串应用之字符串编码转换
[转载]原文地址:https://blog.csdn.net/zhouyong80/article/details/1900100 无论是对程序的本地化还是国际化,都会涉及到字符编码的转换的问题.尤其 ...
随机推荐
- 深入浅出JDBC-操作时间与大对象(Clob/Blob)
一.时间(Date.Time.Timestamp) java.sql.Date/java.sql.Time/java.sql.Timestamp extends java.util.Date publ ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 实战DELPHI:远程线程插入(DLL注入)
http://www.jx19.com/xxzl/Delphi/2010/04/17/ShiZhanDELPHI_YuanChengXianChengChaRu_DLLZhuRu/ 远程注入DLL方法 ...
- MemoryModule -- load a DLL completely from memory
https://github.com/fancycode/MemoryModule MemoryModule is a library that can be used to load a DLL c ...
- directio mysql 编绎选项
http://www.myexception.cn/linux-unix/495407.html http://www.iyunv.com/thread-25950-1-1.html
- 找不到原始安装光盘的佳能EOS Utility的下载和安装
佳能EOS Utility的下载和安装 佳能很有意思,在官方网站上提供的数码相机驱动程序,只是“升级版”,而不是原始安装版.如果我有安装光盘,还去网上下载驱动干吗?解决方案:1,从佳能官方网站上下 ...
- SpringSecurity3整合CAS实现单点登录
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 【redis】spring boot中 使用redis hash 操作 --- 之 使用redis实现库存的并发有序操作
示例: @Autowired StringRedisTemplate redisTemplate; @Override public void dealRedis(Dealer dealer) { d ...
- PHP 输出数据库中文是问号