[HTML] [JavaScript] [tools] converting ASC to Chinese characters and converting Chinese characters to ASC [native2ascii JavaScript implementation (easy to use)]

Source: Internet
Author: User
ASC to Chinese characters and Chinese characters to ASC [native2ascii JavaScript implementation (easy to use)]

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 the JDK 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]

Note: 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 authentication → native authentication @ </title>
<Metaname = "generator" content = "editplus">
<Metaname = "author" content = "szwangdf@163.com">
<Metaname = "keywords" content = "ASC transfer → native transfer authorization">
<Metaname = "Description" content = "ASC authentication → native authentication">
<Script language = "JavaScript">
Function native2ascii (){
VaR Regexp =/[^/x00-/xFF]/g;

VaR n = Document. getelementbyid ("native"). value;
VaR A = N;
While(m=regexp.exe C (n )){
A = A. Split (M [0]). Join (escape (M [0]). Split ("%"). Join ("/"));
}
Document. getelementbyid ("ASCII"). value =;
}

Function ascii2native (){
VaR A = Document. getelementbyid ("ASCII"). value;
VaR n =;
VaR n = Unescape (N. Split ("/"). Join ("% "));
Document. getelementbyid ("native"). value = N;
}
</SCRIPT>
</Head>
<Body>
<H1> ASC syntax → native regression Too many threads: <br>
<Textarea id = "ASCII" rows = "10" Cols = "100"> </textarea> <br>
Keywords: & nbsp;
<Input type = "button" id = "back" value = "commandid encoding → invalid commandid" onclick = "ascii2native ()"/>
& Nbsp;
<Input type = "button" id = "convert" value = "literal =" literal gain "onclick =" native2ascii () "/>
<Br>
<Textarea id = "native" rows = "10" Cols = "100"> </textarea>

</Body>
</Html>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.