gpt4 book ai didi

c# - 对多次编码的字符串进行 HTML/Url 解码

转载 作者:太空狗 更新时间:2023-10-29 23:22:52 25 4
gpt4 key购买 nike

我们有一个从网页中读取的字符串。因为浏览器可以容忍未编码的特殊字符(例如&符号),所以一些使用它的页面进行了编码,而另一些则没有...所以很有可能,我们存储了一些编码一次的数据,而一些编码了多次...

是否有明确的解决方案,如何确保无论编码多少次,我的字符串都已足够解码?

这是我们现在使用的:

public static string HtmlDecode(this string input)
{
var temp = HttpUtility.HtmlDecode(input);
while (temp != input)
{
input = temp;
temp = HttpUtility.HtmlDecode(input);
}
return input;
}

与 UrlDecode 的使用相同。

最佳答案

老实说,这可能是最好的方法。真正的解决方案是重新编写您的代码,以便您只能对所有地方的内容进行单独编码,这样您就只能对它们进行单独解码。

关于c# - 对多次编码的字符串进行 HTML/Url 解码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22822676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com