zoukankan
html css js c++ java
字符编码
aspx页面:
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
CodeNew.aspx.cs
"
Inherits
=
"
CodeNew
"
%>
<!
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
>
无标题页
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
form id
=
"
Form2
"
runat
=
"
server
"
>
请输入字符串:
<
asp:textbox id
=
"
textbox_1
"
runat
=
"
server
"
/>
<
asp:button id
=
"
button_1
"
text
=
"
提交
"
runat
=
"
server
"
/>
<
br
/>
您输入的字符串长度:
<
asp:label id
=
"
label_0
"
runat
=
"
server
"
/><
br
/>
字符码为:
&
nbsp;
<
asp:Label ID
=
"
Label_1
"
runat
=
"
server
"
Text
=
"
Label
"
Width
=
"
50px
"
></
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
/>
</
div
>
</
form
>
</
body
>
</
html
>
C#代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
using
System.Drawing;
using
System.Text;
public
partial
class
CodeNew : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
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);
}
}
Fighting
查看全文
相关阅读:
Windows环境下 配置memcached (php)
谈谈我是怎么学习PHP的(一)
重编译Linux命令源代码
php面向对象学习
Windows文件系统漏洞
十分钟能学会的框架,MVC+20个常用函数
linux系统安装软件方法大全
oracle基本操作
MySQL的limit查询优化
C# winform 可视化操作 Excel文件并读取数据
原文地址:https://www.cnblogs.com/cry/p/610637.html
最新文章
【谭老师讲堂】零基础如何学好Java——鸡汤
【谭老师讲堂】零基础如何学好Java——开胃菜
零基础Java系列【1】——开发环境篇
搭建以太坊POA联盟链
Fabric chaincode开发调试
Hyperledger Fabric概述
HTML 5常用的交互元素————菜单交互元素(1)
HTML 5常用的交互元素————内容交互元素(2)
关于自学Web前端开发(供自己使用)
将博客搬至CSDN
热门文章
学习RaphaelJS矢量图形包--Learning Raphael JS Vector Graphics中文翻译(一)
Hello Point——WebGL
RaphaelJS实践--猫和老鼠矢量图展示
快速上手RaphaelJS--Instant RaphaelJS Starter翻译(三)
快速上手RaphaelJS--Instant RaphaelJS Starter翻译(二)
Professional.WebGL.Programming-Chapter 2(高级WebGL编程——第二章)
快速上手RaphaelJS-Instant RaphaelJS Starter翻译(一)
PHP开发套件
linux 配置 sphinx 全文搜索引擎
关于PHPstorm 使用技巧
Copyright © 2011-2022 走看看