英語で読む

次の方法で共有


Uri.GetLeftPart(UriPartial) メソッド

定義

Uri インスタンスの指定部分を取得します。

C#
public string GetLeftPart(UriPartial part);

パラメーター

part
UriPartial

返される URI 部分の末尾を指定する列挙値。

戻り値

Uri インスタンスの指定部分。

例外

現在の Uri インスタンスは、絶対インスタンスではありません。

指定した part が有効ではありません。

次の例では、 インスタンスを Uri 作成し、コンソールへのパスを書き込みます。

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

注釈

メソッドは GetLeftPart 、URI 文字列の左端の部分を含む文字列を返し、 で part指定された部分で終わる。

GetLeftPart には、次の場合に区切り記号が含まれます。

  • Scheme には、スキーム区切り記号が含まれています。
  • Authority にはパス区切り記号は含まれません。
  • Path には、クエリまたはフラグメント区切り記号までのパス区切り記号と、元の URI 内のすべての区切り記号が含まれます。
  • Query には、 と Pathクエリとその区切り記号が含まれます。

次の例は、URI と、または Queryを使用して AuthorityPathSchemeを呼び出したGetLeftPart結果を示しています。

URI Scheme Authority パス クエリ
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

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1