HttpServerUtility.HtmlDecode 메서드

정의

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

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

오버로드

Name Description
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 문자열입니다.

반품

디코딩된 텍스트입니다.

예제

다음 예제에서는 파일에서 데이터를 디코딩하고 하나의 문자열로 복사하는 함수 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로 인코딩되면 문자열 &lt;&gt;로 변환되고 브라우저에서 부호보다 작고 부호보다 큰 기호가 올바르게 표시됩니다. HtmlDecode 는 서버로 전송된 텍스트를 디코딩합니다.

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

ASP.NET 웹 페이지의 코드 숨김 파일에서 Server 속성을 통해 HttpServerUtility 클래스의 인스턴스에 액세스합니다. 코드 숨김 파일에 없는 클래스에서 클래스의 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로 해석하지 않도록 합니다. 예를 들어 텍스트 문자열에 기호보다 작거나 부호(<)보다 큼이> 포함된 경우 브라우저는 이러한 문자를 HTML 태그의 여는 대괄호 또는 닫는 대괄호로 해석합니다. 문자가 HTML로 인코딩되면 문자열 &lt;&gt;로 변환되고 브라우저에서 부호보다 작고 부호보다 큰 기호가 올바르게 표시됩니다.

HtmlDecode 는 서버로 전송된 텍스트를 디코딩합니다.

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

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

적용 대상