HttpServerUtility.HtmlDecode メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
無効な HTML 文字を排除するためにエンコードされた文字列をデコードします。
Web アプリケーションの外部で値をエンコードまたはデコードするには、 WebUtility クラスを使用します。
オーバーロード
| 名前 | 説明 |
|---|---|
| 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 文字列。
返品
デコードされたテキスト。
例
次の例には、ファイルからデータをデコードして 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 として解釈されないことが確認されます。 たとえば、テキスト文字列に小さい記号 (<) または大きい符号 (>) が含まれている場合、ブラウザーはこれらの文字を HTML タグの開始角かっこまたは終角かっことして解釈します。 文字が HTML エンコードされると、 < および >文字列に変換されます。これにより、ブラウザーに小さい記号とより大きい記号が正しく表示されます。
HtmlDecode は、サーバーに送信されたテキストをデコードします。
このメソッドは、ASP.NET アプリケーションから実行時に HttpUtility.HtmlDecode メソッドにアクセスする便利な方法です。 内部的には、このメソッドは HttpUtility.HtmlDecode を使用して文字列をデコードします。
ASP.NET Web ページの分離コード ファイルで、Server プロパティを使用して HttpServerUtility クラスのインスタンスにアクセスします。 分離コード ファイルにないクラスでは、 HttpContext.Current.Server を使用して、 HttpServerUtility クラスのインスタンスにアクセスします。
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 <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlDecode(EncodedString, writer);
String DecodedString = writer.ToString();
Dim EncodedString As String = "This is a <Test String>."
Dim writer As New StringWriter
Server.HtmlDecode(EncodedString, writer)
Dim DecodedString As String = writer.ToString()
注釈
HTML エンコードでは、テキストがブラウザーに正しく表示され、ブラウザーによって HTML として解釈されないことが確認されます。 たとえば、テキスト文字列に小さい記号 (<) または大きい符号 (>) が含まれている場合、ブラウザーはこれらの文字を HTML タグの開始角かっこまたは終角かっことして解釈します。 文字が HTML エンコードされると、 < および >文字列に変換されます。これにより、ブラウザーに小さい記号とより大きい記号が正しく表示されます。
HtmlDecode は、サーバーに送信されたテキストをデコードします。
HtmlDecode は、ASP.NET アプリケーションから実行時に HttpUtility.HtmlDecode メソッドにアクセスする便利な方法です。 内部的には、 HtmlDecode は HttpUtility.HtmlDecode を使用して文字列をデコードします。
Web アプリケーションの外部で値をエンコードまたはデコードするには、 WebUtility クラスを使用します。