Uri.GetLeftPart(UriPartial) メソッド

定義

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

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

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

返品

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

例外

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

指定した part が無効です。

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

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

注釈

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

Important

GetLeftPartメソッドは、処理の一環として Unicode 文字エンコードと正規化を実行します。 単純な文字列操作メソッドではありません。 このエンコード動作により、返される文字列が元の URI 文字列と異なる場合があります。

GetLeftPart メソッドは、適切なGetComponents フラグを使用してUriComponentsを呼び出すことと同じです。 例えば次が挙げられます。

  • GetLeftPart(UriPartial.Authority)GetComponents(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped) と同じです。

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

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

次の例は、URI と、GetLeftPartSchemeAuthority、またはPathQueryを呼び出した結果を示しています。

URI Scheme 権威 Path Query
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

適用対象