Uri.ToString 메서드

정의

지정된 Uri 인스턴스에 대한 정식 문자열 표현을 가져옵니다.

public:
 override System::String ^ ToString();
public override string ToString ();
override this.ToString : unit -> string
Public Overrides Function ToString () As String

반환

String

이스케이프되지 않은 Uri 인스턴스의 정식 표현입니다. #, ? 및 %를 제외한 모든 문자가 이스케이프되지 않습니다.

예제

다음 예제에서는 문자열에서 새 Uri 인스턴스를 만듭니다. 생성자에 전달된 문자열을 반환하는 값과 문자열의 정식 형식을 반환하는 호출ToString에서 반환OriginalString되는 값의 차이를 보여 줍니다.

// Create a new Uri from a string address.
Uri^ uriAddress = gcnew Uri( "HTTP://www.Contoso.com:80/thick%20and%20thin.htm" );

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version.  OriginalString gives the orginal 
// string that was passed to the constructor.
// The following outputs "http://www.contoso.com/thick and thin.htm".
Console::WriteLine( uriAddress );

// The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
Console::WriteLine( uriAddress->OriginalString );
// Create a new Uri from a string address.
Uri uriAddress = new Uri("HTTP://www.Contoso.com:80/thick%20and%20thin.htm");

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version.  OriginalString gives the orginal
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com/thick and thin.htm".
Console.WriteLine(uriAddress.ToString());

// The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
Console.WriteLine(uriAddress.OriginalString);
// Create a new Uri from a string address.
let uriAddress = Uri "HTTP://www.Contoso.com:80/thick%20and%20thin.htm"

// Write the new Uri to the console and note the difference in the two values.
// ToString() gives the canonical version.  OriginalString gives the orginal
// string that was passed to the constructor.

// The following outputs "http://www.contoso.com/thick and thin.htm".
printfn $"{uriAddress.ToString()}"

// The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
printfn $"{uriAddress.OriginalString}"
    ' Create a new Uri from a string address.
    Dim uriAddress As New Uri("HTTP://www.Contoso.com:80/thick%20and%20thin.htm")
    
    ' Write the new Uri to the console and note the difference in the two values.
    ' ToString() gives the canonical version.  OriginalString gives the orginal 
    ' string that was passed to the constructor.
    ' The following outputs "http://www.contoso.com/thick and thin.htm".
    Console.WriteLine(uriAddress.ToString())
    
    ' The following outputs "HTTP://www.Contoso.com:80/thick%20and%20thin.htm".
    Console.WriteLine(uriAddress.OriginalString)

End Sub

설명

이 메서드에서 반환된 문자열은 포트가 스키마의 기본 포트인 경우 포트 정보를 포함하지 않습니다.

참고

반환한 문자열을 ToString 메서드는 콘솔 애플리케이션의 상태를 손상 시킬 수 있는 제어 문자를 포함할 수 있습니다. 형식이 있는 메서드를 GetComponents 사용하여 반환된 UriFormat.SafeUnescaped 문자열에서 컨트롤 문자를 제거할 수 있습니다.

적용 대상