2012-03-12 157 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)