Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c# urldecode

作者:—上花′Ing   发布日期:2026-03-06   浏览:125

using System;
using System.Web;

class Program
{
    static void Main()
    {
        // 原始编码后的URL字符串
        string encodedUrl = "https%3A%2F%2Fwww.example.com%2Fpath%3Fquery%3Dvalue%26another%3D123";

        // 使用 HttpUtility.UrlDecode 方法解码URL
        string decodedUrl = HttpUtility.UrlDecode(encodedUrl);

        // 输出解码后的URL
        Console.WriteLine("Decoded URL: " + decodedUrl);
    }
}

解释说明:

  1. HttpUtility.UrlDecode:这是 .NET 提供的一个静态方法,用于将经过 URL 编码的字符串解码为原始字符串。
  2. encodedUrl:这是一个经过 URL 编码的字符串,其中特殊字符被替换为 % 加上两位十六进制数表示。
  3. decodedUrl:调用 HttpUtility.UrlDecode 方法后,返回解码后的原始 URL 字符串。
  4. Console.WriteLine:输出解码后的 URL 到控制台。

如果你在项目中使用的是 .NET Core 或 .NET 5+,请确保你已经添加了对 System.Web 的引用。如果使用的是 .NET Core 或更高版本,可以使用 WebUtility.UrlDecode 作为替代。

上一篇:c# checkedlistbox

下一篇:c#控件

大家都在看

c# 二进制

c# 创建目录

c# datatable group by

c# tcp client

c# type.gettype

c# sqlconnection

c# string.format 小数位数

.net和c#

c#获取系统时间

c#游戏开发

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站