[HTML][Javascript][Tools]ASC轉漢字,漢字轉ASC[Native2Ascii的JavaScript實現 (便於平時使用) ]

來源:互聯網
上載者:User
ASC轉漢字,漢字轉ASC[Native2Ascii的JavaScript實現 (便於平時使用) ]

我們常常在編寫Java程式時會用到Properties檔案,把一些Message等資訊放在Properties檔案,但是我們看到的都是一些編碼。

 Struts1.1b2的例子中的本國資源檔經過Unicode編碼的,所以你如果要和它的運行一樣,也必須將你的ApplicationResources_zh進行Unicode編碼。有以下兩種方法:

①使用jdk的native2ascii工具。

native2ascii 功能說明:

將含有本地編碼字元(既非 Latin1 又非 Unicode 字元)的檔案轉換為 Unicode 編碼字元的檔案。

文法:native2ascii [options] [inputfile [outputfile]]

補充說明:Java 編譯器和其它 Java 工具只能處理含有 Latin-1 和/或 Unicode 編碼(udddd 記號)字元的檔案。native2ascii 將含有其它字元編碼的檔案轉換成含 Latin-1 和/或 Unicode 編碼字元的檔案。

若省略 outputfile,則使用標準輸出裝置輸出。

此外,如果也省略 inputfile,則使用標準輸入裝置輸入。

命令選項:

-reverse 執行相反的操作:將含 Latin-1 和/或 Unicode 編碼字元的檔案轉換成含本地編碼字元的檔案。

-encoding[encoding_name] 指定轉換過程使用的編碼名稱。預設的編碼從系統屬性 file.encoding 中得到。

應用執行個體:native2ascii -encoding GBK ApplicationResources.properties ApplicationResources_zh_CN.properties

我的做法:

  1、將存有英文資訊的ApplicationResource.properties複製一份,重新命名為a(為了減少dos命令的長度);

  2、使用Editplus編輯檔案a,寫入中文資訊;3、在Dos視窗中,切換到檔案a所在目錄,運行:native2ascii a ApplicationResource_zh.properties

②我用Javascript寫了一個編碼和漢字互轉的工具。僅供參考。

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
    <TITLE>ASC←→NATIVEツール@杭州の王徳封</TITLE>
    <METANAME="Generator"CONTENT="EditPlus">
    <METANAME="Author"CONTENT="szwangdf@163.com">
    <METANAME="Keywords"CONTENT="ASC←→NATIVEツール">
    <METANAME="Description"CONTENT="ASC←→NATIVEツール">
    <script language="javascript">
        function native2ascii(){
            var regexp=/[^/x00-/xff]/g;

            var n=document.getElementById("native").value;
            var a=n;
            while(m=regexp.exec(n)){
                a=a.split(m[0]).join(escape(m[0]).split("%").join("/"));
            }
            document.getElementById("ascii").value=a;
        }
        
        function ascii2native() {
            var a=document.getElementById("ascii").value;
            var n=a;
            var n=unescape(n.split("/").join("%"));
            document.getElementById("native").value=n;
        }
    </script>
</HEAD>
<BODY>
    <h1>ASC←→NATIVEツール</h1>
    コード :<br>
    <textarea id="ascii" rows="10" cols="100"></textarea><br>
    漢 字:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" id="back"    value="コード→漢字   ↓↓↓" onclick="ascii2native()"/>
    &nbsp;&nbsp;&nbsp;&nbsp;
    <input type="button" id="convert" value="漢字→コード   ↑↑↑" onclick="native2ascii()"/>
    <br>
    <textarea id="native" rows="10" cols="100"></textarea>
    
</BODY>
</HTML>

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.