2012-03-12 67 views
-1

可能重复:
How do I replace all the spaces with %20 in C#URL编码

我正在寻找在C#中的URL编码方法。我知道Server.UrlEncode,但我认为它将空格编码为+符号。我想我记得有一个空间为%20,但不记得它是什么。有没有人知道我还是与其他东西混淆?

+2

请参阅本http://stackoverflow.com/questions/1517586/how-do-i-replace-all-the-spaces-with-20-in-c-sharp – dotoree 2012-03-12 10:52:39

+0

优秀Uri.EscapeDataString是我在找什么。谢谢@dotoree – slimsam86 2012-03-12 10:57:06

回答

1

使用HttpServerUtility.UrlEncode方法(字符串)... URL编码一个字符串并返回编码的字符串。

System.Web.HttpUtility.UrlEncode(string url)