I want to make a string into a URL using C#. There must be something in the .NET framework that should help, right?
Use the String. replace() method to replace all spaces in a string, e.g. str. replace(/ /g, '+'); . The replace() method will return a new string with all spaces replaced by the provided replacement.
There are numerous ways to replace %20 with space. We are going to use the simplest approach which involves the usage of the decodeURIComponent() and trim() methods. The trim() method will remove any extra space at the beginning as well as at the end of the string.
When parsing code, the C compiler ignores white-space characters unless you use them as separators or as components of character constants or string literals. Use white-space characters to make a program more readable. Note that the compiler also treats comments as white space.
For just a space, use ' ' .
Another way of doing this is using Uri.EscapeUriString(stringToEscape)
.
I believe you're looking for HttpServerUtility.UrlEncode.
System.Web.HttpUtility.UrlEncode(string url)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With