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

Definice

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

Parametry

part
UriPartial UriPartial UriPartial UriPartial

Jedna z UriPartial hodnot, která určuje konec části identifikátoru URI, která se má vrátit.One of the UriPartial values that specifies the end of the URI portion to return.

Návraty

, Který obsahuje zadanou část Uri instance. StringA String that contains the specified portion of the Uri instance.

Výjimky

Aktuální Uri instance není absolutní instancí.The current Uri instance is not an absolute instance.

Zadaná part není platná.The specified part is not valid.

Příklady

Následující příklad vytvoří Uri instanci a zapíše cestu k konzole.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

Poznámky

Metoda vrátí řetězec obsahující levou část řetězce identifikátoru URI, končící na část určenou parametrem part. GetLeftPartThe GetLeftPart method returns a string containing the leftmost portion of the URI string, ending with the portion specified by part.

GetLeftPartobsahuje oddělovače v následujících případech:GetLeftPart includes delimiters in the following cases:

  • Schemezahrnuje oddělovač schémat.Scheme includes the scheme delimiter.

  • Authoritynezahrnuje oddělovač cest.Authority does not include the path delimiter.

  • Pathzahrnuje všechny oddělovače v původním identifikátoru URI až do oddělovače dotazu nebo fragmentu.Path includes any delimiters in the original URI up to the query or fragment delimiter.

  • QueryPathzahrnuje a a také dotaz a jeho oddělovač.Query includes the Path, plus the query and its delimiter.

Následující příklady znázorňují identifikátor URI a výsledky volání GetLeftPart s Scheme, Authority, Pathnebo Query.The following examples show a URI and the results of calling GetLeftPart with Scheme, Authority, Path, or Query.

Identifikátor URIURI SchémaScheme DohledAuthority CestaPath DotazyQuery
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

Platí pro