Uri.Segments プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定した URI を構成するパス セグメントを格納している配列を取得します。
public:
property cli::array <System::String ^> ^ Segments { cli::array <System::String ^> ^ get(); };
public string[] Segments { get; }
member this.Segments : string[]
Public ReadOnly Property Segments As String()
- String[]
指定した URI を構成するパス セグメント。
このインスタンスは相対 URI を表します。このプロパティは、絶対 URI でのみ有効です。
次の例では、 Uri 3 つのセグメントを持つインスタンスを作成し、画面にセグメントを表示します。
Uri^ uriAddress1 = gcnew Uri( "http://www.contoso.com/title/index.htm" );
Console::WriteLine( "The parts are {0}, {1}, {2}", uriAddress1->Segments[ 0 ], uriAddress1->Segments[ 1 ], uriAddress1->Segments[ 2 ] );
Uri uriAddress1 = new Uri("http://www.contoso.com/title/index.htm");
Console.WriteLine("The parts are {0}, {1}, {2}", uriAddress1.Segments[0], uriAddress1.Segments[1], uriAddress1.Segments[2]);
let uriAddress1 = Uri "http://www.contoso.com/title/index.htm"
printfn $"The parts are {uriAddress1.Segments[0]}, {uriAddress1.Segments[1]}, {uriAddress1.Segments[2]}"
Dim uriAddress1 As New Uri("http://www.contoso.com/title/index.htm")
Console.WriteLine("The parts are {0}, {1}, {2}", uriAddress1.Segments(0), uriAddress1.Segments(1), uriAddress1.Segments(2))
このプロパティは Segments 、URI の絶対パスを形成する "segments" (部分文字列) を含む文字列の配列を返します。 最初のセグメントは、スラッシュ (/) またはパスの末尾に到達するまで、最初の文字から絶対パスを解析することによって取得されます。 各追加セグメントは、前のセグメントの後の最初の文字で始まり、次のスラッシュまたはパスの末尾で終了します。 (URI の絶対パスには、ホストとポートの後、およびクエリとフラグメントの前にあるすべてのものが含まれています)。
次の例は、2 つの URI の絶対パスとセグメントを示しています。 2 番目の例は、フラグメントとクエリが絶対パスの一部ではないため、セグメントではないことを示しています。
絶対 URI: http://www.contoso.com/Chapters/Chapter1/Sections/Section1.htm
絶対パス: /Chapters/Chapter1/Sections/Section1.htm
セグメント:
- /
- Chapters/
- 第 1 章/
- セクション/
- Section1.htm
絶対 URI: http://www.contoso.com/Chapters/Chapter1/Sections/Section1.htm#page1?answer=NO
絶対パス: /Chapters/Chapter1/Sections/Section1.htm
セグメント:
- /
- Chapters/
- 第 1 章/
- セクション/
- Section1.htm
絶対パスは '/' で始まるので、最初のセグメントはそれを含み、それ以外は何も含めないでください。
製品 | バージョン |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7 |
.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 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |