可以使用System.Web命名空间下的HttpUtility.UrlEncode方法来将字符串转换为URL编码。

示例代码:

string str = "hello world";
string urlEncodedStr = HttpUtility.UrlEncode(str);
Console.WriteLine(urlEncodedStr); // 输出:hello+world

注意:在使用HttpUtility.UrlEncode方法时,需要在代码文件开头引入System.Web命名空间,如下所示:

using System.Web;
c# 字符转urlcode

原文地址: https://www.cveoy.top/t/topic/7fm 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录