Use kernel32.dll to convert simplified and traditional Chinese characters

Source: Internet
Author: User

Page code:

<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default4.aspx. cs" inherits = "default4" %>

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: Label id = "label1" runat = "server" text = "I am a Chinese user! "> </ASP: Label>
<Asp: button id = "button1" runat = "server" text = "simplified" onclick = "btnchs_click"/>
<Asp: button id = "button2" runat = "server" text = "traditional" onclick = "btncht_click"/>
</Div>
</Form>
</Body>
</Html>

 

Logical implementation:

 

Using system;
Using system. collections;
Using system. configuration;
Using system. Data;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. xml. LINQ;
Using system. runtime. interopservices;
Using system. text;

Public partial class default4: system. Web. UI. Page
{
// 2. Import kernel32.dll
// Copy and save
[Dllimport ("kernel32.dll", entrypoint = "lcmapstringa")]
Public static extern int lcmapstring (
Int locale,
Int dwmapflags,
Byte [] lpsrcstr,
Int cchsrc,
Byte [] lpdeststr,
Int cchdest );

Const int lcmap_simplified_chinese = 0x02000000;
Const int lcmap_traditional_chinese = 0x04000000;

Protected void page_load (Object sender, eventargs E)
{

}

// 3. Convert to simplified
// Copy and save
Protected void btnchs_click (Object sender, eventargs E)
{
String src = label1.text. Trim ();
Byte [] srcbyte = encoding. Default. getbytes (SRC );
Byte [] desbyte = new byte [srcbyte. Length];
Lcmapstring (2052, lcmap_simplified_chinese, srcbyte,-1, desbyte, srcbyte. Length );
String des = encoding. Default. getstring (desbyte );
Label1.text = des;
}

// 4. Convert to traditional Chinese
// Copy and save
Protected void btncht_click (Object sender, eventargs E)
{
String src = label1.text. Trim ();
Byte [] srcbyte = encoding. Default. getbytes (SRC );
Byte [] desbyte = new byte [srcbyte. Length];

Lcmapstring (2052, lcmap_traditional_chinese, srcbyte,-1, desbyte, srcbyte. Length );
String des = encoding. Default. getstring (desbyte );
Label1.text = des;
}

 

}

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.