Uri.GetLeftPart(UriPartial) Uri.GetLeftPart(UriPartial) Uri.GetLeftPart(UriPartial) Uri.GetLeftPart(UriPartial) Method

Définition

Obtient la partie spécifiée d'une instance Uri.Gets the specified portion of a Uri instance.

public:
 System::String ^ GetLeftPart(UriPartial part);
public string GetLeftPart (UriPartial part);
member this.GetLeftPart : UriPartial -> string
Public Function GetLeftPart (part As UriPartial) As String

Paramètres

part
UriPartial UriPartial UriPartial UriPartial

L'une des valeurs UriPartial qui spécifie la fin de la partie de l'URI à retourner.One of the UriPartial values that specifies the end of the URI portion to return.

Retours

String qui contient la partie spécifiée de l'instance de Uri.A String that contains the specified portion of the Uri instance.

Exceptions

L'instance de Uri en cours n'est pas une instance absolue.The current Uri instance is not an absolute instance.

La valeur part spécifiée n'est pas valide.The specified part is not valid.

Exemples

L’exemple suivant crée une instance Uri et écrit le chemin d’accès à la console.The following example creates a Uri instance and writes the path to the console.

// Create Uri
Uri^ uriAddress = gcnew Uri( "http://www.contoso.com/index.htm#search" );
Console::WriteLine( uriAddress->Fragment );
Console::WriteLine( "Uri {0} the default port ", uriAddress->IsDefaultPort ? (String^)"uses" : "does not use" );

Console::WriteLine( "The path of this Uri is {0}", uriAddress->GetLeftPart( UriPartial::Path ) );
Console::WriteLine( "Hash code {0}", uriAddress->GetHashCode() );
// The example displays the following output:
//        #search
//        Uri uses the default port
//        The path of this Uri is http://www.contoso.com/index.htm
//        Hash code -988419291
// Create Uri
Uri uriAddress = new Uri("http://www.contoso.com/index.htm#search");
Console.WriteLine(uriAddress.Fragment);
Console.WriteLine("Uri {0} the default port ", uriAddress.IsDefaultPort ? "uses" : "does not use");
 
Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path));
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode());
// The example displays the following output:
//        #search
//        Uri uses the default port
//        The path of this Uri is http://www.contoso.com/index.htm
//        Hash code -988419291
' Create Uri
Dim uriAddress As New Uri("http://www.contoso.com/index.htm#search")
Console.WriteLine(uriAddress.Fragment)
Console.WriteLine("Uri {0} the default port ", If(uriAddress.IsDefaultPort, "uses", "does not use")) 

Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path))
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode())
' The example displays the following output:
'        #search
'        Uri uses the default port
'        The path of this Uri is http://www.contoso.com/index.htm
'        Hash code -988419291

Remarques

La méthode GetLeftPart retourne une chaîne contenant la partie la plus à gauche de la chaîne d’URI, se terminant par la partie spécifiée par part.The GetLeftPart method returns a string containing the leftmost portion of the URI string, ending with the portion specified by part.

GetLeftPart comprend des délimiteurs dans les cas suivants :GetLeftPart includes delimiters in the following cases:

  • Scheme comprend le délimiteur de schéma.Scheme includes the scheme delimiter.

  • Authority n’inclut pas le délimiteur de chemin d’accès.Authority does not include the path delimiter.

  • Path comprend tous les délimiteurs de l’URI d’origine jusqu’à la requête ou au délimiteur de fragment.Path includes any delimiters in the original URI up to the query or fragment delimiter.

  • Query comprend la Path, plus la requête et son délimiteur.Query includes the Path, plus the query and its delimiter.

Les exemples suivants illustrent un URI et les résultats de l’appel de GetLeftPart avec Scheme, Authority, Path ou Query.The following examples show a URI and the results of calling GetLeftPart with Scheme, Authority, Path, or Query.

URIURI SchemeScheme AutorisationsAuthority Chemin d’accèsPath QueryQuery
http://www.contoso.com/index.htm?date=today http:// http://www.contoso.com http://www.contoso.com/index.htm http://www.contoso.com/index.htm?date=today
http://www.contoso.com/index.htm#main http:// http://www.contoso.com http://www.contoso.com/index.htm http://www.contoso.com/index.htm
mailto:user@contoso.com?subject=uri mailto: mailto:user@contoso.com mailto:user@contoso.com?subject=uri <none>
nntp://news.contoso.com/123456@contoso.com nntp:// nntp://news.contoso.com nntp://news.contoso.com/123456@contoso.com nntp://news.contoso.com/123456@contoso.com
news:123456@contoso.com news: news:123456@contoso.com news:123456@contoso.com <none>
file://server/filename.ext file:// file://server file://server/filename.ext file://server/filename.ext

S’applique à