Share via


HttpServerUtility.HtmlDecode 메서드

정의

잘못된 HTML 문자를 제거하기 위해 인코딩된 문자열을 디코딩합니다.

웹 애플리케이션 외부의 값을 인코딩 또는 디코딩하려면 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 문자열입니다.

반환

String

디코딩된 텍스트입니다.

예제

다음 예제에는 파일에서 데이터를 디코딩하고 하나의 문자열로 복사하는 함수 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 는 서버로 전송된 텍스트를 디코딩합니다.

이 방법은 편리 하 게 액세스를 HttpUtility.HtmlDecode ASP.NET 애플리케이션에서 런타임 시 메서드. 내부적으로 이 메서드는 문자열을 디코딩하는 데 사용합니다 HttpUtility.HtmlDecode .

ASP.NET 웹 페이지의 코드 숨김 파일에서 속성을 통해 클래스의 인스턴스에 HttpServerUtility 액세스합니다Server. 코드 숨김 파일에 없는 클래스에서 클래스의 HttpServerUtility 인스턴스에 액세스하는 데 사용합니다HttpContext.Current.Server.

웹 애플리케이션을 외부에서 사용할는 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 <Test String>."라는 DecodedString 문자열에 복사합니다.

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 편리 하 게 액세스 되는 HttpUtility.HtmlDecode ASP.NET 애플리케이션에서 런타임에 메서드. 내부적으로 HtmlDecode 문자열을 디코딩하는 데 사용합니다 HttpUtility.HtmlDecode .

웹 애플리케이션 외부의 값을 인코딩 또는 디코딩하려면 WebUtility 클래스를 사용합니다.

적용 대상