Uri.ToString メソッド
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した Uri インスタンスの正規文字列表現を取得します。
public:
override System::String ^ ToString();
C#
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 = 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 );
C#
// 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 使用して、返された文字列から制御文字を削除できます。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |