如何在c#中编码字符串? [英] how can I encode string in c#?

查看:68
本文介绍了如何在c#中编码字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中编码字符串?



i add using system.web

我的代码是:

 字符串 TestString =  这是一个< Test String>。; 
字符串 EncodedString = Server.HtmlEncode(TestString);









System.Web.HttpUtility.HtmlEncode

但是我不能用这个

解决方案

Server.HtmlEncode 是旧ASP方法中常用的旧方法。你应该使用 System.Net.WebUtility.HtmlEncode ,它支持4& 4.5。对于旧版本,请使用 System.Web.HttpServerUtility.HtmlEncode



问候,


C#中的字符串编码..



例如:



1)用C#完成HTML字符编码



2) .NET类库中的Html编码

System.Web.HttpUtility.HtmlEncode(你的文字)


how can I encode string in c#?

i add using system.web
and my code is:

String TestString = "This is a <Test String>.";
String EncodedString = Server.HtmlEncode(TestString);




or
System.Web.HttpUtility.HtmlEncode
but i can't use this

解决方案

Server.HtmlEncode is a old method typically used in old ASP pages. You shoud use System.Net.WebUtility.HtmlEncode, it is supported in 4 & 4.5. For older versions use System.Web.HttpServerUtility.HtmlEncode.

Regards,


String Encoding in C#..

Eg:

1 )Full HTML Character Encoding in C#

2 )Html encoding in .NET class library


System.Web.HttpUtility.HtmlEncode("YOUR TEXT")


这篇关于如何在c#中编码字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆