Uri.GetLeftPart 方法
返回 Uri 实例中的指定部分。
**命名空间:**System
**程序集:**System(在 system.dll 中)
语法
声明
Public Function GetLeftPart ( _
part As UriPartial _
) As String
用法
Dim instance As Uri
Dim part As UriPartial
Dim returnValue As String
returnValue = instance.GetLeftPart(part)
public string GetLeftPart (
UriPartial part
)
public:
String^ GetLeftPart (
UriPartial part
)
public String GetLeftPart (
UriPartial part
)
public function GetLeftPart (
part : UriPartial
) : String
参数
- part
UriPartial 值之一,指定要返回的 URI 部分的结尾。
返回值
一个 String,其中包含 Uri 实例的指定部分。
异常
异常类型 | 条件 |
---|---|
当前 Uri 实例不是绝对实例。 |
|
指定的 part 无效。 |
备注
GetLeftPart 方法返回一个包含 URI 字符串中最左边部分的字符串,它以 part 指定的部分结束。
在下面的情况下,GetLeftPart 包括分隔符:
下面的示例演示了一个 URI 以及使用 Scheme、Authority、Path 或 Query 调用 GetLeftPart 的结果。
URI |
方案 |
颁发机构 |
路径 |
查询 |
---|---|---|---|---|
https://www.contoso.com/index.htm?date=today |
http:// |
https://www.contoso.com |
https://www.contoso.com/index.htm |
https://www.contoso.com/index.htm?date=today |
https://www.contoso.com/index.htm#main |
http:// |
https://www.contoso.com |
https://www.contoso.com/index.htm |
https://www.contoso.com/index.htm |
mailto:user@contoso.com?subject=uri |
mailto: |
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: |
news:123456@contoso.com |
news:123456@contoso.com |
<无> |
file://server/filename.ext |
file:// |
file://server |
file://server/filename.ext |
file://server/filename.ext |
示例
下面的示例创建一个 Uri 实例并将路径输出到控制台。
' Create Uri
Dim uriAddress As New Uri("https://www.contoso.com/index.htm#search")
Console.WriteLine(uriAddress.Fragment)
Console.WriteLine("Uri {0} the default port ", IIf(uriAddress.IsDefaultPort, "uses", "does not use")) 'TODO: For performance reasons this should be changed to nested IF statements
Console.WriteLine("The path of this Uri is {0}", uriAddress.GetLeftPart(UriPartial.Path))
Console.WriteLine("Hash code {0}", uriAddress.GetHashCode())
// Create Uri
Uri uriAddress = new Uri("https://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());
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0