c# html decode,C# HtmlDecode、HtmlEncode、UrlEncode、UrlDecode

不用System.Web 对 Content进行编码,De编码

string content = "
";

string s1 = WebUtility.HtmlEncode(content);

string s3 = WebUtility.HtmlDecode(s1);

string s4 = WebUtility.UrlEncode(content);

eba631564b87f31b88eda742b23eb0fa.png

using System.IO;

namespace System.Net

{

//

// 摘要:

// Provides methods for encoding and decoding URLs when processing Web requests.

public static class WebUtility

{

//

// 摘要:

// Converts a string that has been HTML-encoded for HTTP transmission into a decoded

// string.

//

// 参数:

// value:

// The string to decode.

//

// 返回结果:

// A decoded string.

public static string HtmlDecode(string value);

//

// 摘要:

// Converts a string that has been HTML-encoded into a decoded string, and sends

// the decoded string to a System.IO.TextWriter output stream.

//

// 参数:

// value:

// The string to decode.

//

// output:

// A System.IO.TextWriter stream of output.

//

// 异常:

// T:System.ArgumentNullException:

// The output parameter cannot be null if the value parameter is not null.

public static void HtmlDecode(string value, TextWriter output);

//

// 摘要:

// Converts a string to an HTML-encoded string.

//

// 参数:

// value:

// The string to encode.

//

// 返回结果:

// An encoded string.

public static string HtmlEncode(string value);

//

// 摘要:

// Converts a string into an HTML-encoded string, and returns the output as a System.IO.TextWriter

// stream of output.

//

// 参数:

// value:

// The string to encode.

//

// output:

// A System.IO.TextWriter output stream.

//

// 异常:

// T:System.ArgumentNullException:

// The output parameter cannot be null if the value parameter is not null.

public static void HtmlEncode(string value, TextWriter output);

//

// 摘要:

// Converts a string that has been encoded for transmission in a URL into a decoded

// string.

//

// 参数:

// encodedValue:

// A URL-encoded string to decode.

//

// 返回结果:

// Returns System.String. A decoded string.

public static string UrlDecode(string encodedValue);

//

// 摘要:

// Converts an encoded byte array that has been encoded for transmission in a URL

// into a decoded byte array.

//

// 参数:

// encodedValue:

// A URL-encoded System.Byte array to decode.

//

// offset:

// The offset, in bytes, from the start of the System.Byte array to decode.

//

// count:

// The count, in bytes, to decode from the System.Byte array.

//

// 返回结果:

// Returns System.Byte. A decoded System.Byte array.

public static byte[] UrlDecodeToBytes(byte[] encodedValue, int offset, int count);

//

// 摘要:

// Converts a text string into a URL-encoded string.

//

// 参数:

// value:

// The text to URL-encode.

//

// 返回结果:

// Returns System.String. A URL-encoded string.

public static string UrlEncode(string value);

//

// 摘要:

// Converts a byte array into a URL-encoded byte array.

//

// 参数:

// value:

// The System.Byte array to URL-encode.

//

// offset:

// The offset, in bytes, from the start of the System.Byte array to encode.

//

// count:

// The count, in bytes, to encode from the System.Byte array.

//

// 返回结果:

// Returns System.Byte. An encoded System.Byte array.

public static byte[] UrlEncodeToBytes(byte[] value, int offset, int count);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值