Uri.GetLeftPart(UriPartial) Metoda

Definice

Získá zadanou Uri část 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

Parametry

part
UriPartial

Jedna z hodnot výčtu, která určuje konec části identifikátoru URI, která se má vrátit.

Návraty

Zadaná část Uri instance.

Výjimky

Aktuální Uri instance není absolutní instancí.

part Zadaný parametr není platný.

Příklady

Následující příklad vytvoří Uri instanci a zapíše cestu ke konzole.

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

Poznámky

Metoda GetLeftPart vrátí řetězec obsahující nejvíce levou část řetězce identifikátoru URI, končící částí určenou part.

Important

Metoda GetLeftPart provádí kódování znaků Unicode a normalizaci v rámci svého zpracování. Nejedná se o jednoduchou metodu manipulace s řetězci. Vrácený řetězec se může lišit od původního řetězce identifikátoru URI kvůli tomuto chování kódování.

Metoda GetLeftPart je ekvivalentní volání GetComponents s příslušnými UriComponents příznaky. Příklad:

  • GetLeftPart(UriPartial.Authority) je ekvivalentní GetComponents(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped)

GetLeftPart obsahuje oddělovače v následujících případech:

  • Scheme obsahuje oddělovač schématu.
  • Authority neobsahuje oddělovač cesty.
  • Path obsahuje oddělovač cest a všechny oddělovače v původním identifikátoru URI až do dotazu nebo oddělovače fragmentů.
  • Query obsahuje , Pathplus dotaz a jeho oddělovač.

Následující příklady ukazují identifikátor URI a výsledky volání GetLeftPart pomocí Scheme, Authority, Path, nebo Query.

identifikátor URI Scheme Autorita Cesta Query
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

Platí pro