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

c# url解码

作者:白话少年的痴情梦—   发布日期:2026-02-26   浏览:34

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);
    }
}

解释说明:

  1. 引入命名空间System.Web 提供了 HttpUtility 类,其中包含用于 URL 编码和解码的方法。
  2. 定义编码后的 URLencodedUrl 是一个包含百分号编码字符(如 %20 表示空格)的字符串。
  3. 解码 URL:使用 HttpUtility.UrlDecode 方法将编码后的 URL 转换为原始字符串。
  4. 输出结果:分别打印编码前和解码后的 URL 以验证解码是否成功。

如果你在项目中没有引用 System.Web 命名空间,可以通过 NuGet 包管理器安装 System.Net.WebUtility 或其他替代方案。

上一篇:c# gui

下一篇: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 中文站