Uri.ToString メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した Uri インスタンスの正規文字列表現を取得します。
public:
override System::String ^ ToString();
public override string ToString();
override this.ToString : unit -> string
Public Overrides Function ToString () As String
返品
Uri インスタンスのエスケープされていない正規表現。 #、?、および %を除くすべての文字はエスケープされません。
例
次の例では、文字列から新しい Uri インスタンスを作成します。 コンストラクターに渡された文字列を返す OriginalStringから返される値と、文字列の正規形式を返す ToStringの呼び出しから返される値の違いを示しています。
// 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
注釈
このメソッドによって返される文字列には、ポートがスキームの既定のポートである場合、ポート情報は含まれません。
Note
ToString メソッドによって返される文字列には制御文字が含まれている可能性があり、コンソール アプリケーションの状態が破損する可能性があります。 GetComponents メソッドをUriFormat.SafeUnescaped形式で使用すると、返された文字列から制御文字を削除できます。