I have a string that represents that name of an entity. The name of this entity has a dash in it (-). How can I encode the dash? I believe it should be encoded to '%2D' but when I try encodeURIComponent() or encodeURI() for that matter, it doesn't encode the dash. I was just wondering if there is an encode function that will encode the dash rather than just doing a .replace
- is a character that appears in the ASCII character set and has no special meaning in URLs. While you can encode it as %2D, doing so is not needed nor is it normal. Encoding it would be like using %61 instead of a.
There is no standard encoding function that will encode a - character. replace is the logical choice if you really, really want to.
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