HttpServerUtility.HtmlDecode メソッド

定義

エンコードされた文字列をデコードして、無効な HTML 文字を削除します。

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

オーバーロード

HtmlDecode(String)

HTML エンコードされた文字列をデコードし、デコードした文字列を返します。

HtmlDecode(String, TextWriter)

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

HtmlDecode(String)

HTML エンコードされた文字列をデコードし、デコードした文字列を返します。

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

パラメーター

s
String

デコードする HTML 文字列。

戻り値

String

デコードされたテキスト。

次の例には、ファイルからデータをデコードして 1 つの文字列にコピーする関数 LoadDecodedFileが含まれています。

<%@ PAGE LANGUAGE = "C#" %>
 <%@ IMPORT NAMESPACE = "System.IO" %>
 
 <html xmlns="http://www.w3.org/1999/xhtml">
 <script runat ="server">
 
    String LoadDecodedFile(String file)
       {
       String DecodedString = "";
       FileStream fs = new FileStream(file, FileMode.Open);
       StreamReader r = new StreamReader(fs);
 
       // Position the file pointer at the beginning of the file.
       r.BaseStream.Seek(0, SeekOrigin.Begin);
       
       // Read the entire file into a string and decode each chunk.  
       while (r.Peek() > -1)
          DecodedString += Server.HtmlDecode(r.ReadLine());
 
       r.Close();
       return DecodedString; 
       }
 
 </script>
 <head runat="server">
 <title>HttpServerUtility.HtmlDecode Example</title>
 </head>
 <body></body>
 </html>

<%@ PAGE LANGUAGE = "VB" %>
<%@ Import Namespace="System.IO" %>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<script runat = "server">
 
   Function LoadDecodedFile(file As String) As String
      Dim DecodedString As String
      Dim fs As New FileStream(file, FileMode.Open)
      Dim r As New StreamReader(fs)
      ' Position the file pointer at the beginning of the file.
      r.BaseStream.Seek(0, SeekOrigin.Begin)
      ' Read the entire file into a string and decode each chunk.
      Do While r.Peek() > -1
         DecodedString = DecodedString & _
            Server.HtmlDecode(r.ReadLine())
      Loop
      r.Close()
      LoadDecodedFile = DecodedString
   End Function
 
</script>
<head runat="server">
    <title> HttpServerUtility.HtmlDecode Example</title>
</head>
<body></body>
</html>

注釈

HTML エンコードでは、テキストがブラウザーに正しく表示され、ブラウザーによって HTML として解釈されないことが確認されます。 たとえば、テキスト文字列に小さい符号 (<) or greater than sign (>) が含まれている場合、ブラウザーはこれらの文字を HTML タグの開始角かっこまたは終了角かっことして解釈します。 文字が HTML エンコードされると、文字列&lt;``&gt;に変換され、ブラウザーに小さい符号とより大きい符号が正しく表示されます。 HtmlDecode は、サーバーに送信されたテキストをデコードします。

このメソッドは、ASP.NET アプリケーションから実行時にHttpUtility.HtmlDecodeメソッドにアクセスする便利な方法です。 内部的には、このメソッドは文字列のデコードに使用 HttpUtility.HtmlDecode します。

ASP.NET Web ページの分離コード ファイルで、プロパティを介してクラスのインスタンスにHttpServerUtilityServerアクセスします。 分離コード ファイルに含まれていないクラスでは、クラスのHttpServerUtilityインスタンスにアクセスするために使用HttpContext.Current.Serverします。

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

適用対象

HtmlDecode(String, TextWriter)

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

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

パラメーター

s
String

デコードする HTML 文字列。

output
TextWriter

デコードされた文字列を格納する TextWriter 出力ストリーム。

次の例では、HTTP 経由で送信するために HTML エンコードされた文字列をデコードします。 "This is a Test String>" というテキストを含む指定EncodedStringされた文字列をデコードし、"This is a ." という名前DecodedStringの<Test String>文字列にコピーします。<

String EncodedString = "This is a &ltTest String&gt.";
StringWriter writer = new StringWriter();
Server.HtmlDecode(EncodedString, writer);
String DecodedString = writer.ToString();

Dim EncodedString As String = "This is a &ltTest String&gt."
Dim writer As New StringWriter
Server.HtmlDecode(EncodedString, writer)
Dim DecodedString As String = writer.ToString()
   

注釈

HTML エンコードでは、テキストがブラウザーに正しく表示され、ブラウザーによって HTML として解釈されないことが確認されます。 たとえば、テキスト文字列に小さい符号 (<) or greater than sign (>) が含まれている場合、ブラウザーはこれらの文字を HTML タグの開始角かっこまたは終了角かっことして解釈します。 文字が HTML エンコードされると、文字列&lt;``&gt;に変換され、ブラウザーに小さい符号とより大きい符号が正しく表示されます。

HtmlDecode は、サーバーに送信されたテキストをデコードします。

HtmlDecodeは、ASP.NET アプリケーションから実行時にHttpUtility.HtmlDecodeメソッドにアクセスする便利な方法です。 内部的には、 HtmlDecode 文字列のデコードに使用 HttpUtility.HtmlDecode されます。

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

適用対象