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

定义

获取 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

参数

part
UriPartial UriPartial UriPartial UriPartial

UriPartial 值之一,指定要返回的 URI 部分的结尾。One of the UriPartial values that specifies the end of the URI portion to return.

返回

一个 String,其中包含 Uri 实例的指定部分。A String that contains the specified portion of the Uri instance.

异常

当前 Uri 实例不是绝对实例。The current Uri instance is not an absolute instance.

指定的 part 无效。The specified part is not valid.

示例

下面的示例创建Uri实例并将路径输出到控制台。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

注解

GetLeftPart方法返回一个包含与指定的部分结束的 URI 字符串的最左侧部分字符串partThe GetLeftPart method returns a string containing the leftmost portion of the URI string, ending with the portion specified by part.

GetLeftPart 在以下情况下包括分隔符:GetLeftPart includes delimiters in the following cases:

  • Scheme 包括方案分隔符。Scheme includes the scheme delimiter.

  • Authority 不包括路径分隔符。Authority does not include the path delimiter.

  • Path 最多的查询或片段的分隔符的原始 URI 中包括任何分隔符。Path includes any delimiters in the original URI up to the query or fragment delimiter.

  • Query 包括Path,加上查询和其分隔符。Query includes the Path, plus the query and its delimiter.

下面的示例演示将 URI 和调用的结果GetLeftPartSchemeAuthorityPath,或QueryThe following examples show a URI and the results of calling GetLeftPart with Scheme, Authority, Path, or Query.

URIURI 方案Scheme 颁发机构Authority 路径Path 查询Query
http://www.contoso.com/index.htm?date=today http://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:// http://www.contoso.com http://www.contoso.com/index.htm http://www.contoso.com/index.htm
mailto:user@contoso.com?subject=urimailto:user@contoso.com?subject=uri mailto:mailto: mailto:user@contoso.com mailto:user@contoso.com?subject=urimailto:user@contoso.com?subject=uri <none><none>
nntp://news.contoso.com/123456@contoso.com nntp://nntp:// nntp://news.contoso.comnntp://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><none>
file://server/filename.extfile://server/filename.ext file://file:// file://serverfile://server file://server/filename.extfile://server/filename.ext file://server/filename.extfile://server/filename.ext

适用于