Uri.EscapeUriString(String) Uri.EscapeUriString(String) Uri.EscapeUriString(String) Uri.EscapeUriString(String) Method

定义

将 URI 字符串转换为它的转义表示形式。Converts a URI string to its escaped representation.

public:
 static System::String ^ EscapeUriString(System::String ^ stringToEscape);
public static string EscapeUriString (string stringToEscape);
static member EscapeUriString : string -> string
Public Shared Function EscapeUriString (stringToEscape As String) As String

参数

stringToEscape
String String String String

要转义的字符串。The string to escape.

返回

一个 String,包含 stringToEscape 的转义表示形式。A String that contains the escaped representation of stringToEscape.

异常

适用于 Windows 应用商店应用的 .NET可移植类库中,改为捕获基类异常 FormatExceptionIn the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, FormatException, instead.

stringToEscape 的长度超过 32766 个字符。The length of stringToEscape exceeds 32766 characters.

注解

使用方法可将非转义 URI 字符串准备为Uri构造函数的参数。 EscapeUriStringUse the EscapeUriString method to prepare an unescaped URI string to be a parameter to the Uri constructor.

默认情况下, EscapeUriString方法将除 RFC 2396 不保留字符之外的所有字符转换为其十六进制表示形式。By default, the EscapeUriString method converts all characters, except RFC 2396 unreserved characters, to their hexadecimal representation. 如果启用了 "国际资源标识符 (IRIs)" 或 "国际化域名 (IDN) 分析EscapeUriString ", 则方法会将除 RFC 3986 不保留字符之外的所有字符转换为其十六进制表示形式。If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing is enabled, the EscapeUriString method converts all characters, except for RFC 3986 unreserved characters, to their hexadecimal representation. 在转义之前, 所有 Unicode 字符都将转换为 UTF-8 格式。All Unicode characters are converted to UTF-8 format before being escaped.

此方法假定stringToEscape它中没有转义序列。This method assumes that stringToEscape has no escape sequences in it.

默认情况下, 根据 RFC 2396 对字符串进行转义。By default, the string is escaped according to RFC 2396. 如果启用了 "国际资源标识符 (IRIs)" 或 "国际化域名 (IDN) 分析", 则根据 RFC 3986 和 RFC 3987 对该字符串进行转义。If International Resource Identifiers (IRIs) or Internationalized Domain Name (IDN) parsing is enabled, the string is escaped according to RFC 3986 and RFC 3987. 有关保留和未保留字符的定义, 请参阅这些 Rfc。See these RFCs for a definition of reserved and unreserved characters.

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

适用于