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()
属性值
构成指定 URI 的路径段。
例外
此实例表示相对 URI,此属性仅对绝对 URI 有效。
示例
以下示例创建一个包含 3 个 Uri 段的实例,并在屏幕上显示段。
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 绝对路径的“段”(子字符串)。 第一段是通过分析第一个字符的绝对路径来获取的,直到到达斜杠(/)或路径末尾。 每个附加段在上一段之后的第一个字符开始,并用下一个斜杠或路径的末尾终止。 (URI 的绝对路径包含主机和端口之后以及查询和片段之前的所有内容。
以下示例显示了两个 URI 的绝对路径和段。 第二个示例说明片段和查询不是绝对路径的一部分,因此不是段。
绝对 URI: http://www.contoso.com/Chapters/Chapter1/Sections/Section1.htm
绝对路径:/Chapters/Chapter1/Sections/Section1.htm
段:
- /
- 章/
- 第 1 章/
- 部分/
- Section1.htm
绝对 URI: http://www.contoso.com/Chapters/Chapter1/Sections/Section1.htm#page1?answer=NO
绝对路径:/Chapters/Chapter1/Sections/Section1.htm
段:
- /
- 章/
- 第 1 章/
- 部分/
- Section1.htm
请注意,由于绝对路径以“/”开头,因此第一段包含它,没有其他内容。