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;
}
}