次の方法で共有


HttpServerUtility.HtmlDecode メソッド (String)

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

Overloads Public Function HtmlDecode( _
   ByVal s As String _) As String
[C#]
public string HtmlDecode(strings);
[C++]
public: String* HtmlDecode(String* s);
[JScript]
public function HtmlDecode(
   s : String) : String;

パラメータ

  • s
    デコードする HTML 文字列。

戻り値

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

解説

URL をエンコーディングすると、すべてのブラウザは URL 文字列のテキストを正常に送信します。ブラウザによっては、"?"、"&"、"/"、空白などの文字が切り捨てられる場合や正しく表示されない場合があります。そのため、これらの文字は、<A> タグやクエリ文字列ではエンコードする必要があります。これらのタグやクエリに指定した文字列は、ブラウザによって要求文字列の一部として送信される可能性があるためです。

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

使用例

[Visual Basic, C#, JScript] ファイルからのデータをデコードして、そのデータを 1 つの文字列にコピーする関数 LoadDecodedFile を格納する例を次に示します。

 
<%@ PAGE LANGUAGE = VB %>
<%@ IMPORT NAMESPACE = System.IO %>
 
<html>
<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>
</html>


[C#] 
<%@ PAGE LANGUAGE = C# %>
 <%@ IMPORT NAMESPACE = System.IO %>
 
 <html>
 <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>
 </html>


[JScript] 
<%@ PAGE LANGUAGE = JSCRIPT %>
<%@ IMPORT NAMESPACE = System.IO %>
 
<html>
<script runat = server>
 
   function LoadDecodedFile(file : String) : String{
      var decodedString : String
      var fs : FileStream = new FileStream(file, FileMode.Open)
      var r : StreamReader = 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 = decodedString + Server.HtmlDecode(r.ReadLine())
      }
      r.Close()
      return decodedString
   }

</script>
</html>

[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

HttpServerUtility クラス | HttpServerUtility メンバ | System.Web 名前空間 | HttpServerUtility.HtmlDecode オーバーロードの一覧