Create URL Encoded String

I’m passing an affiliate marketing link to the user, and it includes a random code which could itself include a character that needs encoding.

But no worries, I can pass the url encoded random code from the server side.