Uri.GetComponents(UriComponents, UriFormat) Uri.GetComponents(UriComponents, UriFormat) Uri.GetComponents(UriComponents, UriFormat) Uri.GetComponents(UriComponents, UriFormat) Method

定义

使用特殊字符的指定转义,获取当前实例的指定部分。Gets the specified components of the current instance using the specified escaping for special characters.

public:
 System::String ^ GetComponents(UriComponents components, UriFormat format);
public string GetComponents (UriComponents components, UriFormat format);
member this.GetComponents : UriComponents * UriFormat -> string
Public Function GetComponents (components As UriComponents, format As UriFormat) As String

参数

components
UriComponents UriComponents UriComponents UriComponents

UriComponents 值的按位组合,它指定当前实例中要返回到调用方的部分。A bitwise combination of the UriComponents values that specifies which parts of the current instance to return to the caller.

format
UriFormat UriFormat UriFormat UriFormat

UriFormat 值中的一个,它控制如何转义特殊字符。One of the UriFormat values that controls how special characters are escaped.

返回

一个包含这些部分的 StringA String that contains the components.

异常

components 不是有效 UriComponents 值的组合。components is not a combination of valid UriComponents values.

当前 Uri 不是绝对 URI。The current Uri is not an absolute URI. 相对 URI 不能和此方法一起使用。Relative URIs cannot be used with this method.

注解

QueryFragment 、、Port、、和Path组件不包含分隔符。 Host Scheme UserInfoThe Query, Fragment, Scheme, UserInfo, Host, Port, and Path components do not include the delimiter. 可以将KeepDelimiter标志 (使用按位 "或" 运算符) 与任何这些值结合使用来获取带有分隔符的值。You can combine the KeepDelimiter flag (using the bitwise OR operator) with any of those values to get the value with the delimiter. 对于所有其他UriComponents值和值的组合, 分隔符包含在返回值中。For all other UriComponents values, and combinations of values, the delimiters are included in the returned value.

组件按照其在 URI 中出现的顺序返回。The components are returned in the order that they appear in the URI. 例如, 如果Scheme指定了, 则它将首先出现。For example, if Scheme is specified, it appears first.

启用国际资源标识符 (IRI) 和国际化域名 (IDN) 支持后, 返回String的字符数将增加。When International Resource Identifier (IRI) and Internationalized Domain Name (IDN) support are enabled, the number of characters returned in the String increases. 用于支持 IRI 的 Punycode 名称只包含 ASCII 字符, 并且始终以 xn--前缀开头。Punycode names used to support IRI contain only ASCII characters and always start with the xn-- prefix. 启用 IRI 和 IDN 后, GetComponents方法将正确处理 Unicode 代理项字符。When IRI and IDN are enabled, Unicode surrogate characters are handled correctly by the GetComponents method.

有关 IRI 支持的详细信息, 请参阅Uri类的 "备注" 部分。For more information on IRI support, see the Remarks section for the Uri class.

备注

如果在GetComponents format设置UriUnescaped的情况下调用方法, 则不能将返回值用作构造函数的自变量来创建等效Uri的。If the GetComponents method is called with format set to Unescaped , you cannot use the return value as an argument to a Uri constructor to create an equivalent Uri.

适用于