Uri.GetLeftPart(UriPartial) メソッド

定義

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

返される URI 部分の末尾を指定する列挙値。One of the enumeration values that specifies the end of the URI portion to return.

戻り値

String

Uri インスタンスの指定部分。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 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
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
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 ます。The 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 と GetLeftPart 、、、、またはを使用したの呼び出しの結果を示して Scheme Authority Path Query います。The following examples show a URI and the results of calling GetLeftPart with Scheme, Authority, Path, or Query.

URIURI SchemeScheme AuthorityAuthority PathPath クエリ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: 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

適用対象