C# 中的 Uri.EscapeDataString(String) 方法
csharpserver side programmingprogramming更新于 2025/9/24 12:07:17
C# 中的 Uri.EscapeDataString() 方法将字符串转换为其转义表示形式。
语法
以下是语法 −
public static string EscapeDataString (string str);
以上,字符串 str 是需要转义的字符串。
示例
现在让我们看一个实现 Uri.EscapeDataString() 方法的示例 −
using System;
public class Demo {
public static void Main(){
string URI1 = "https://www.tutorialspoint.com/index.htm";
Console.WriteLine("URI = "+URI1);
string URI2 = "https://www.tutorialspoint.com/";
Console.WriteLine("URI = "+URI2);
Console.WriteLine("
Escaped string (URI1) = "+Uri.EscapeDataString(URI1));
Console.WriteLine("Escaped string (URI2) = "+Uri.EscapeDataString(URI2));
}
}
输出
这将产生以下输出 −
URI = https://www.tutorialspoint.com/index.htm URI = https://www.tutorialspoint.com/ Escaped string (URI1) = https%3A%2F%2Fwww.tutorialspoint.com%2Findex.htm Escaped string (URI2) = https%3A%2F%2Fwww.tutorialspoint.com%2F

