zoukankan      html  css  js  c++  java
  • C# HtmlDecode、HtmlEncode、UrlEncode、UrlDecode

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


    string content = "<br/>";
    string s1 = WebUtility.HtmlEncode(content);

    string s3 = WebUtility.HtmlDecode(s1);

    string s4 = WebUtility.UrlEncode(content);

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

  • 相关阅读:
    WinForm获取窗体关闭原因和是否取消关闭值
    DIV CSS 居中代码(以及靠右)
    C#获取本机所有IP地址(包括局域网和本机外网IP)
    C# WinForm关闭窗体确认
    .NET WinForm全屏和退出以及蓝屏黑屏等
    HTML5标签
    C# 文件、文件夹操作语句(删除,创建,移动,检查是否存在)
    jquery聚焦文本框
    JS当前页面登录注册框,固定DIV,底层阴影
    Visual Studio 怎样添加引用
  • 原文地址:https://www.cnblogs.com/micro-chen/p/11557838.html
Copyright © 2011-2022 走看看