HttpUtility.HtmlDecode メソッド

定義

HTTP 転送用に HTML エンコードされた文字列をデコードされた文字列に変換します。

Web アプリケーションの外部で値をエンコードまたはデコードするには、 WebUtility クラスを使用します。

オーバーロード

名前 説明
HtmlDecode(String)

HTTP 転送用に HTML エンコードされた文字列をデコードされた文字列に変換します。

HtmlDecode(String, TextWriter)

HTML エンコードされた文字列をデコードされた文字列に変換し、デコードされた文字列を TextWriter 出力ストリームに送信します。

HtmlDecode(String)

HTTP 転送用に HTML エンコードされた文字列をデコードされた文字列に変換します。

public:
 static System::String ^ HtmlDecode(System::String ^ s);
public static string HtmlDecode(string s);
static member HtmlDecode : string -> string
Public Shared Function HtmlDecode (s As String) As String

パラメーター

s
String

デコードする文字列。

返品

デコードされた文字列。

次のコード例は、HttpUtility クラスのHtmlEncodeメソッドとHtmlDecode メソッドを示しています。 入力文字列は、 HtmlEncode メソッドを使用してエンコードされます。 取得したエンコードされた文字列は、 HtmlDecode メソッドを使用してデコードされます。

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}");
    }
}
Imports System.Web
Imports System.IO

Class MyNewClass
   Public Shared Sub Main()
      Dim myString As String
      Console.WriteLine("Enter a string having '&' or '""'  in it: ")
      myString = Console.ReadLine()
      Dim myEncodedString As String
      ' Encode the string.
      myEncodedString = HttpUtility.HtmlEncode(myString)
      Console.WriteLine("HTML Encoded string is " + myEncodedString)
      Dim myWriter As New StringWriter()
      ' Decode the encoded string.
      HttpUtility.HtmlDecode(myEncodedString, myWriter)
      Console.Write("Decoded string of the above encoded string is " + myWriter.ToString())
   End Sub
End Class

注釈

空白や句読点などの文字が HTTP ストリームで渡されると、受信側で誤って解釈される可能性があります。 HTML エンコードは、HTML で許可されていない文字を文字エンティティに変換します。HTML デコードはエンコードを反転します。 たとえば、テキスト ブロックに埋め込まれる場合、文字 < と > は、HTTP 送信用に &lt; および &gt; としてエンコードされます。

Web アプリケーションの外部で値をエンコードまたはデコードするには、 WebUtility クラスを使用します。

こちらもご覧ください

適用対象

HtmlDecode(String, TextWriter)

HTML エンコードされた文字列をデコードされた文字列に変換し、デコードされた文字列を TextWriter 出力ストリームに送信します。

public:
 static void HtmlDecode(System::String ^ s, System::IO::TextWriter ^ output);
public static void HtmlDecode(string s, System.IO.TextWriter output);
static member HtmlDecode : string * System.IO.TextWriter -> unit
Public Shared Sub HtmlDecode (s As String, output As TextWriter)

パラメーター

s
String

デコードする文字列。

output
TextWriter

出力の TextWriter ストリーム。

注釈

空白や句読点などの文字が HTTP ストリームで渡されると、受信側で誤って解釈される可能性があります。 HTML エンコードは、HTML で許可されていない文字を文字エンティティに変換します。HTML デコードはエンコードを反転します。 たとえば、テキスト ブロックに埋め込まれる場合、文字 < と > は、HTTP 送信用に &lt; および &gt; としてエンコードされます。

Web アプリケーションの外部で値をエンコードまたはデコードするには、 WebUtility クラスを使用します。

こちらもご覧ください

適用対象