温馨提示×

如何在C#中对URL进行解码操作

c#
小樊
142
2024-08-08 05:02:51
栏目: 编程语言

在C#中进行URL解码操作可以使用System.Web.HttpUtility类的UrlDecode方法。示例如下:

using System;
using System.Web;

class Program
{
    static void Main()
    {
        string url = "https://www.example.com/search?q=%E6%90%9C%E7%B4%A2";
        string decodedUrl = HttpUtility.UrlDecode(url);
        
        Console.WriteLine(decodedUrl);
    }
}

在上面的示例中,我们首先创建一个URL字符串,然后使用UrlDecode方法对其进行解码操作,最后输出解码后的URL。在这个例子中,输出结果将是"https://www.example.com/search?q=搜索"。

0