I want to use java’s URLEncoder class to encode my url strings. However, by default it converts spaces to ‘+’ (plus sign). I’d like it to use ‘-‘ instead (similar to how this site encodes its urls).
I’m wondering what the best way to do this is? Should I just use its built in functionality and then do a string replace (from ‘+’ to ‘-‘)? Thanks
The
URLEncoderencodes the URL’s according a specific contract. You can and should not change it. Indeed just do a string replace afterwards, or maybe better, beforehand. The hyphen-is namely already a valid character in URL.