Uri.ToString Methode

Definition

Ruft eine kanonische Zeichenfolgendarstellung für die angegebene Uri Instanz ab.

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

Gibt zurück

Die nicht gescapete kanonische Darstellung der Uri Instanz. Alle Zeichen sind mit Ausnahme von "#", "?" und "%" nicht dargestellt.

Beispiele

Im folgenden Beispiel wird eine neue Uri Instanz aus einer Zeichenfolge erstellt. Es veranschaulicht den Unterschied zwischen dem zurückgegebenen OriginalStringWert, der die Zeichenfolge zurückgibt, die an den Konstruktor übergeben wurde, und von einem Aufruf an ToString, der die kanonische Form der Zeichenfolge zurückgibt.

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

Hinweise

Die von dieser Methode zurückgegebene Zeichenfolge enthält keine Portinformationen, wenn der Port der Standardport für das Schema ist.

Note

Die von der ToString Methode zurückgegebene Zeichenfolge kann Steuerzeichen enthalten, die den Zustand einer Konsolenanwendung beschädigen können. Sie können die GetComponents Methode mit dem UriFormat.SafeUnescaped Format verwenden, um Steuerzeichen aus der zurückgegebenen Zeichenfolge zu entfernen.

Gilt für: