I want to make a string into a URL using C#. There must be something in the .NET framework that should help, right?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Another way of doing this is using
Uri.EscapeUriString(stringToEscape)
.Use
HttpServerUtility.UrlEncode
HttpServerUtility.HtmlEncode
From the documentation:
But this actually encodes HTML, not URLs. Instead use UrlEncode(TestString).
As commented on the approved story, the HttpServerUtility.UrlEncode method replaces spaces with + instead of %20. Use one of these two methods instead: Uri.EscapeUriString() or Uri.EscapeDataString()
Sample code: