using System;
using System.Web;
class Program
{
static void Main()
{
// 定义一个需要解码的URL字符串
string encodedUrl = "https://example.com/path%20with%20spaces?query=hello%20world";
// 使用HttpUtility.UrlDecode方法进行解码
string decodedUrl = HttpUtility.UrlDecode(encodedUrl);
// 输出解码后的结果
Console.WriteLine("Encoded URL: " + encodedUrl);
Console.WriteLine("Decoded URL: " + decodedUrl);
}
}
System.Web 提供了 HttpUtility 类,其中包含用于 URL 编码和解码的方法。encodedUrl 是一个包含百分号编码字符(如 %20 表示空格)的字符串。HttpUtility.UrlDecode 方法将编码后的 URL 转换为原始字符串。如果你在项目中没有引用 System.Web 命名空间,可以通过 NuGet 包管理器安装 System.Net.WebUtility 或其他替代方案。
上一篇:c# gui
下一篇:c#复制文件夹到指定文件夹
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站