I am in a sitauation where I have some path. This path could be something like “jadajada.com/My Site.html”.
I use HttpUtility.UrlEncode to encode the urls, which is great. However, I have the issue that whenever I have a space, it replaces this with a “+” sign. I need a “-” sign instead.
Can this method perform this task? And if so, what kind of encoding ect.
(And yes, I know you can use string.Replace, but please avoid that solution for now 😉
Replacing spaces with
"-"is not really encoding, since there is no standard decoder for that; the"+"is correct.However, if this is for display only, and as long as your code doesn’t rely on this value (for example, to do an exact slug match expecting the space) you could simply do a
.Replace(" ","-")before you encode. In that lossy scenario you might also want to replace a few others, truncate overly long strings, etc.Encoding it once it has a
-should be a no-op (i.e. it won’t change).