将特殊字符转换为常规C# [英] Converting special characters to regular c#

查看:76
本文介绍了将特殊字符转换为常规C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#中是否有一条命令可将类似以下的字符串转换为: https%3A%2F%2Fwww.google.com 回到 https://www.google.com ?

Is there a command in C# to convert strings like : https%3A%2F%2Fwww.google.com back to https://www.google.com?

也许是某种解密"方法?

some sort of "decryption" method maybe?

推荐答案

您需要为此使用 System.Web.HttpUtility.UrlDecode :

string real = System.Web.HttpUtility.UrlDecode(encodedString);

您可以使用反向功能 System.Web.HttpUtility.UrlEncode 进行编码.

You can use the reverse function System.Web.HttpUtility.UrlEncode to encode.

这与加密或解密无关.只是某些字符不能表示为参数的一部分或URL中的其他字符.例如,冒号(:)不能作为URL尾部的一部分,因为它在前缀(http :)中使用,因此它被编码为%3A.

This is not a matter of encryption or decryption. It is just that some characters cannot be expressed as part of parameters or other in a URL. For instance, a colon (:) cannot be part of a URL tail because it is used in the prefix (http:), so it gets encoded as %3A.

以相同的方式,斜杠被编码为%2F.因此,%3A%2F2%F表示://.

In the same way, a slash gets encoded as %2F. Hence, %3A%2F2%F means ://.

这篇关于将特殊字符转换为常规C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆