/
,:
等。所以
"http://www.example.com/my cool page"
将被编码为
"http://www.example.com/my%20cool%20page"
.NET中有什么东西要做到这一点吗?或者是正则表达式我最好的选择?
答案 0 :(得分:5)
尝试
Uri.EscapeUriString("http://www.mysite.com/my cool page")
答案 1 :(得分:1)
尝试
Server.URLEncode(uri.ToString)
答案 2 :(得分:1)
试试这个:
HttpUtility.UrlEncode(String)
例如:
var url_encoded_string = HttpUtility.UrlEncode(userInput);
答案 3 :(得分:0)
您可以使用System.Net.WebUtility.UrlEncode(string value)
。