Uri.GetLeftPart(UriPartial) Methode

Definition

Ruft den angegebenen Teil einer Uri Instanz ab.

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

Parameter

part
UriPartial

Einer der Enumerationswerte, die das Ende des zurückzugebenden URI-Teils angibt.

Gibt zurück

Der angegebene Teil der Uri Instanz.

Ausnahmen

Die aktuelle Uri Instanz ist keine absolute Instanz.

Der angegebene part Wert ist ungültig.

Beispiele

Im folgenden Beispiel wird eine Uri Instanz erstellt und der Pfad zur Konsole geschrieben.

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

Hinweise

Die GetLeftPart Methode gibt eine Zeichenfolge zurück, die den äußerst linken Teil der URI-Zeichenfolge enthält und mit dem durch partangegebenen Teil endet.

Important

Die GetLeftPart Methode führt unicode-Zeichencodierung und Normalisierung als Teil der Verarbeitung durch. Es handelt sich nicht um eine einfache Zeichenfolgenmanipulationsmethode. Die zurückgegebene Zeichenfolge kann sich aufgrund dieses Codierungsverhaltens von der ursprünglichen URI-Zeichenfolge unterscheiden.

Die GetLeftPart Methode entspricht dem Aufrufen GetComponents mit den entsprechenden UriComponents Flags. Beispiel:

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

GetLeftPart enthält Trennzeichen in den folgenden Fällen:

  • Scheme enthält das Schematrennzeichen.
  • Authority enthält das Pfadtrennzeichen nicht.
  • Path enthält das Pfadtrennzeichen und alle Trennzeichen im ursprünglichen URI bis zum Abfrage- oder Fragmenttrennzeichen.
  • Query enthält die PathAbfrage und das Zugehörige Trennzeichen.

Die folgenden Beispiele zeigen einen URI und die Ergebnisse des Aufrufens GetLeftPart mit Scheme, , Authority, Pathoder Query.

URI Scheme Autorität Pfad Abfrage
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

Gilt für: