Using JavaScript to convert ASC to Chinese characters and Chinese characters to ASC, javascriptasc
This example describes how to use JavaScript to convert ASC to Chinese characters and Chinese characters to ASC. We will share this with you for your reference. The details are as follows:
We often use the Properties file when writing Java programs, and put some messages and other information in the Properties file, but we see some encoding.
The source file in the Struts1.1b2 example is Unicode encoded, so if you want to run the same as it, you must also encode your ApplicationResources_zh. There are two methods:
① Use jdk's native2ascii Tool.
Native2ascii function description:
Convert a file that contains both local and non-Unicode characters to a Unicode character.
Syntax: Native2ascii [options] [inputfile [outputfile]
Additional instructions: The Java compiler and other Java tools can only process files containing Latin-1 and/or Unicode (udddd mark) characters. Native2ascii converts a file containing other character encoding into a file containing Latin-1 and/or Unicode encoding characters.
If outputfile is omitted, the standard output device is used.
In addition, if inputfile is also omitted, standard input is used for device input.
Command Options:
-Reverse: convert a file containing Latin-1 and/or Unicode characters to a file containing local encoding characters.
-Encoding [encoding_name] specifies the encoding name used in the conversion process. The default encoding is obtained from the system property file. encoding.
Application Example: native2ascii-encoding GBK ApplicationResources. properties ApplicationResources_zh_CN.properties
My practices:
1. Copy ApplicationResource. properties with English information and rename it as a (to reduce the doscommand length );
2. Use Editplus to edit file a and write Chinese information. 3. In the Dos window, switch to the directory where File a is located and run: native2ascii a ApplicationResource_zh.properties.
② I used Javascript to write a tool for encoding and conversion of Chinese characters.. For reference only.
<! DOCTYPEHTMLPUBLIC "-// W3C // DTDHTML4.0Transitional/EN"> <HTML> <HEAD> <TITLE> ASC syntax → NATIVE Neural Networks @ Hangzhou の </TITLE> <METANAME = "Generator" CONTENT = "EditPlus"> <METANAME = "Author" CONTENT = "szwangdf@163.com"> <METANAME = "Keywords" CONTENT = "ASC authentication → NATIVE authentication Authentication "> <METANAME =" Description "CONTENT =" ASC transfer → NATIVE Transfer Protocol "> <script language =" javascript "> function native2ascii () {var regexp =/[^/x00-/xff]/g; var n = document. getElementById ("native "). value; var a = n; while(m1_regexp.exe c (n) {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>
I hope this article will help you design JavaScript programs.
Articles you may be interested in:
- Share Chinese character-to-pinyin code using javascript
- Javascript limits that users can only enter Chinese Characters
- Javascript Regular Expressions match Chinese characters, numbers, letters, and underscores
- Conversion code of Chinese characters and Unicode codes in javascript
- Code for converting javascript Chinese characters to PinYin
- Javascript Chinese Character byte judgment
- Sample Code for sorting Chinese characters using JavaScript
- Simplified Chinese character conversion using javascript
- How to transmit Chinese characters through URLs in JavaScript
- Conversion of javascript Chinese characters and Pinyin
- Code for converting javascript Chinese characters to PinYin