Uri.GetComponents(UriComponents, UriFormat) 方法

定义

使用特殊字符的指定转义,获取当前实例的指定部分。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 值的按位组合,它指定当前实例中要返回到调用方的部分。A bitwise combination of the UriComponents values that specifies which parts of the current instance to return to the caller.

format
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.

注解

QueryFragmentSchemeUserInfoHostPortPath 组件不包含分隔符。The 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.

备注

如果在将 format 设置为 Unescaped 的情况下调用 GetComponents 方法,则不能将返回值用作 Uri 构造函数的参数以创建等效的 UriIf 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.

适用于