HttpUtility.HtmlEncode 方法

地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.web.httputility.htmlencode?redirectedfrom=MSDN&view=netframework-4.8#overloads

代码示例:

using System;
using System.Web;
using System.IO;

class MyNewClass
{
    public static void Main()
    {
        Console.WriteLine("Enter a string having '&', '<', '>' or '"' in it: ");
        string myString = Console.ReadLine();

        // Encode the string.
        string myEncodedString = HttpUtility.HtmlEncode(myString);

        Console.WriteLine($"HTML Encoded string is: {myEncodedString}");
        StringWriter myWriter = new StringWriter();

        // Decode the encoded string.
        HttpUtility.HtmlDecode(myEncodedString, myWriter);

        string myDecodedString = myWriter.ToString();
        Console.Write($"Decoded string of the above encoded string is: {myDecodedString}");
    }
}

总结:文档演示了,HttpUtility.HtmlEncode方法,将字符串编码成了什么。

原文地址:https://www.cnblogs.com/Tpf386/p/11906680.html