Uri.ToString Methode

Definitie

Hiermee haalt u een canonieke tekenreeksweergave op voor het opgegeven Uri exemplaar.

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

Retouren

De ongezichtige canonieke weergave van het Uri exemplaar. Alle tekens zijn ongezichtloos, behalve #, ?, en %.

Voorbeelden

In het volgende voorbeeld wordt een nieuw Uri exemplaar gemaakt op basis van een tekenreeks. Het illustreert het verschil tussen de waarde die wordt geretourneerd van OriginalString, waarmee de tekenreeks wordt geretourneerd die is doorgegeven aan de constructor, en van een aanroep naar ToString, die de canonieke vorm van de tekenreeks retourneert.

// 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

Opmerkingen

De tekenreeks die door deze methode wordt geretourneerd, bevat geen poortgegevens wanneer de poort de standaardpoort voor het schema is.

Note

De tekenreeks die door de ToString methode wordt geretourneerd, kan besturingstekens bevatten, waardoor de status van een consoletoepassing kan worden beschadigd. U kunt de GetComponents methode met de UriFormat.SafeUnescaped notatie gebruiken om besturingstekens uit de geretourneerde tekenreeks te verwijderen.

Van toepassing op