Uri.GetLeftPart(UriPartial) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient la partie spécifiée d’une 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
Une des valeurs d’énumération qui spécifie la fin de la partie URI à retourner.
Retours
Partie spécifiée de l’instance Uri .
Exceptions
L’instance actuelle Uri n’est pas une instance absolue.
La valeur spécifiée part n’est pas valide.
Exemples
L’exemple suivant crée une Uri instance et écrit le chemin d’accès à la console.
// 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 output similar to the following:
// #search
// Uri uses the default port
// The path of this Uri is http://www.contoso.com/index.htm
// Hash code -988419291
// Create Uri
let uriAddress = Uri "http://www.contoso.com/index.htm#search"
printfn $"{uriAddress.Fragment}"
printfn $"""Uri {if uriAddress.IsDefaultPort then "uses" else "does not use"} the default port """
printfn $"The path of this Uri is {uriAddress.GetLeftPart UriPartial.Path}"
printfn $"Hash code {uriAddress.GetHashCode()}"
// The example displays output similar to the following:
// #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 output similar to the following:
' #search
' Uri uses the default port
' The path of this Uri is http://www.contoso.com/index.htm
' Hash code -988419291
Remarques
La GetLeftPart méthode 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.
Important
La GetLeftPart méthode effectue l’encodage de caractères Unicode et la normalisation dans le cadre de son traitement. Il ne s’agit pas d’une méthode de manipulation de chaîne simple. La chaîne retournée peut différer de la chaîne d’URI d’origine en raison de ce comportement d’encodage.
La GetLeftPart méthode équivaut à appeler GetComponents avec les indicateurs appropriés UriComponents . Par exemple:
-
GetLeftPart(UriPartial.Authority)équivaut àGetComponents(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped)
GetLeftPart inclut des délimiteurs dans les cas suivants :
- Scheme inclut le délimiteur de schéma.
- Authority n’inclut pas le délimiteur de chemin d’accès.
- Path inclut le délimiteur de chemin d’accès et tous les délimiteurs de l’URI d’origine jusqu’à la requête ou au délimiteur de fragment.
- Query inclut la Pathrequête, ainsi que son délimiteur.
Les exemples suivants montrent un URI et les résultats de l’appel GetLeftPart avec Scheme, , Authorityou PathQuery.
| URI | Scheme | Autorité | Path | Requête |
|---|---|---|---|---|
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: |
<none> |
mailto:user@contoso.com |
mailto:user@contoso.com?subject=uri |
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: |
<none> |
news:123456@contoso.com |
news:123456@contoso.com |
file://server/filename.ext |
file:// |
file://server |
file://server/filename.ext |
file://server/filename.ext |