本文介绍了如何将HTML编码的字符串转换为普通字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某些互联网地址是html编码的,我想解码为普通字符串。例如,http%3A%3D%3Dgoogle%2Ecom到http://google.com。我该怎么办?

Some internet addresses are html encoded and I want to decode to normal strings. For example http%3A%3D%3Dgoogle%2Ecom to http://google.com. How can I do simply?

推荐答案

using System.Net; // add this at the top of your code file
// the code to decode:
string input = "http%3A%3D%3Dgoogle%2Ecom";
string decoded = WebUtility.UrlDecode(input);



WebUtility类不存在在旧版本中,如果您使用较旧的.NET版本,请添加对System.Web的引用并使用此代码:


The WebUtility class doesn't exist in older versions, so if you use an older .NET version, add a reference to System.Web and use this code:

using System.Web; // add this at the top of your code file
// the code to decode:
string input = "http%3A%3D%3Dgoogle%2Ecom";
string decoded = HttpUtility.UrlDecode(input);



注意:上面的代码转换它进入 http:== google.com 而不是 http://google.com ,因为%3D 不代表斜线。如果你想要斜杠,请使用%2F


Note: the above code transforms it into http:==google.com and not http://google.com, because %3D doesn't represent a slash. Use %2F if you want a slash.


这篇关于如何将HTML编码的字符串转换为普通字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:20