Uri.ToString Uri.ToString Uri.ToString Uri.ToString Method

Definición

Obtiene una representación de cadena canónica para la instancia de Uri especificada.Gets a canonical string representation for the specified Uri instance.

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

Devoluciones

Instancia de String que contiene la representación canónica sin escape de la instancia de Uri.A String instance that contains the unescaped canonical representation of the Uri instance. Todos son caracteres sin escape, excepto #, ? y %.All characters are unescaped except #, ?, and %.

Ejemplos

En el ejemplo siguiente se crea una nueva instancia de Uri a partir de una cadena.The following example creates a new Uri instance from a string. Muestra la diferencia entre el valor devuelto de OriginalString, que devuelve la cadena que se pasó al constructor y de una llamada a ToString, que devuelve la forma canónica de la cadena.It illustrates the difference between the value returned from OriginalString, which returns the string that was passed to the constructor, and from a call to ToString, which returns the canonical form of the string.

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

Comentarios

La cadena devuelta por este método no contiene información de puerto cuando el puerto es el puerto predeterminado para el esquema.The string returned by this method does not contain port information when the port is the default port for the scheme.

Nota

La cadena devuelta por el método ToString puede contener caracteres de control, que pueden dañar el estado de una aplicación de consola.The string returned by the ToString method may contain control characters, which can corrupt the state of a console application. Puede usar el método GetComponents con el formato UriFormat.SafeUnescaped para quitar los caracteres de control de la cadena devuelta.You can use the GetComponents method with the UriFormat.SafeUnescaped format to remove control characters from the returned string.

Seguridad

SecurityPermission
para evitar que el código de confianza parcial derive de Uri.to prevent partially trusted code from deriving from Uri. Enumeración asociada: Infrastructure.Associated enumeration: Infrastructure.

Se aplica a