在URL解码外语字符 [英] Decoding foreign language characters in url
问题描述
我用HTTPUtility.URLDe code解码在URL中的字符。以下是文字我必须去code:
I am decoding characters in a URL by using HTTPUtility.URLDecode. Here are the characters I have to decode:
26%=与&
%28 =(
%29 =)
%20 =
%5B =[
%5D =]
%2C =,
%23 =#
%F3 =O(西班牙语字符)
%26 = "&"
%28 = "("
%29 = ")"
%20 = " "
%5B = "["
%5D = "]"
%2C = ","
%23 = "#"
%F3 = "ó" (spanish character)
HTTPUtility.URLDe code的伟大工程上的所有,但最后一个。我做了查找/替换上最后一个字符的权利,但希望能有更好的自动的方式,所以我没有更新查找/替换的未来。
HTTPUtility.URLDecode works great on all but the last one. I am doing a find/replace on that last character right now, but hoping there is a better automatic way so I don't have to update the find/replace in the future.
推荐答案
您应该使用的 HttpUtility.UrlDe $的C $ C()
接受编码过载:
You should use an overload of HttpUtility.UrlDecode()
that accepts an encoding:
HttpUtility.UrlDecode("%F3", Encoding.GetEncoding("ISO-8859-1"))
此假设它实际上是使用ISO-8859-1编码。如果使用Windows 1250,您应该使用。 (这两个都非常相似,但它们是不相同的。)
This assumes it actually is using the ISO-8859-1 encoding. If it uses Windows-1250, you should use that. (These two are very similar, but they are not the same.)
这篇关于在URL解码外语字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!