<%@ Page Language="C#" AutoEventWireup="True" Debug="true" ValidateRequest="false" %>
<Script language="C#" runat="server">
void Page_Load(Object Sender,EventArgs e){
if (!Page.IsPostBack){
Response.Write("还没有输入任何字符!<br><br>");
}
else{
Label_1.Text="";
Label_2.Text="";
Label_0.Text=Convert.ToString((TextBox_1.Text).Length);
//ASCII编码输出
ByteFunction(TextBox_1.Text);
//字符码输出
CharFunction(TextBox_1.Text);
//HTML编码输出
HtmlFunction(TextBox_1.Text);
}
}
//ASCII编码输出函数
void ByteFunction(string str){
Byte[] MyBytes=System.Text.Encoding.ASCII.GetBytes(str);
for (int i=0;i<str.Length;i++){
Label_2.Text+=Convert.ToString(MyBytes[i])+" ";
}
}
//字符码输出函数
void CharFunction(string str){
Byte[] MyBytes=System.Text.Encoding.ASCII.GetBytes(str);
Char[] MyChars=System.Text.Encoding.ASCII.GetChars(MyBytes);
//Label_2.Text=new string(MyChars);
for (int i=0;i<str.Length;i++){
Label_1.Text+=Convert.ToString(MyChars[i])+" ";
}
}
//HTML编码输出函数
void HtmlFunction(string str){
string Str_Html=(Server.HtmlEncode(str));
Label_3.Text=Str_Html;
Label_4.Text=Server.HtmlEncode(Str_Html);
}
</Script>
<form runat="server">
请输入字符串:
<asp:TextBox ID="TextBox_1" runat="server"/>
<asp:button ID="Button_1" Text="提交" runat="server"/>
</form>
您输入的字符串长度:
<asp:label ID="Label_0" runat="server"/><br>
字符码为:
<asp:label ID="Label_1" runat="server"></asp:label><br>
ASCII码编码:
<asp:label ID="Label_2" runat="server"></asp:label><br>
HTML编码为:
<asp:label ID="Label_3" runat="server"></asp:label><br>
HTML编码以字符输出:
<asp:label ID="Label_4" runat="server"/><br>
本文地址:http://com.8s8s.com/it/it8591.htm