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

c# urlencode

作者:迷失未来   发布日期:2026-02-19   浏览:14

using System;
using System.Web;

class Program
{
    static void Main()
    {
        string originalString = "https://example.com/path?param1=value1&param2=value 2";
        string encodedString = HttpUtility.UrlEncode(originalString);

        Console.WriteLine("Original String: " + originalString);
        Console.WriteLine("Encoded String: " + encodedString);
    }
}

解释说明:

  • HttpUtility.UrlEncode 是 C# 中用于对 URL 进行编码的方法,它会将 URL 中的特殊字符(如空格、&、= 等)转换为 URL 编码格式。
  • 在上面的代码中,我们定义了一个原始的 URL 字符串 originalString,然后使用 HttpUtility.UrlEncode 方法对其进行编码,并将结果存储在 encodedString 变量中。
  • 最后,通过 Console.WriteLine 输出原始字符串和编码后的字符串,以便对比查看编码效果。

如果你需要解码 URL 编码后的字符串,可以使用 HttpUtility.UrlDecode 方法。

上一篇:c# list 去重

下一篇:c# do while

大家都在看

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 中文站