tip_URLEncode + instead of %20

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
trmpluym
Posts: 304
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

tip_URLEncode + instead of %20

Post by trmpluym »

Dear friends,

To use an WEB API call I am required to encode a string with URLEncode

https://en.wikipedia.org/wiki/Percent-encoding

In Harbour this can be done using the tip_URLEncode function (HBTIP Library).

So I tried the simple line below:

Code: Select all

MsgDebug( tip_URLEncode("Microsoft Office") )
I was expecting the result below:

Code: Select all

Microsoft%20Office
But instead I got:

Code: Select all

Microsoft+Office
I found out both "+" and "%20" are used to replace a SPACE character.

In the link below the statement is "%20" is more modern:

https://stackoverflow.com/questions/163 ... cter-or-20

Is there a modified version or alternative function to do the URLEncoding ?

Best regards,

Theo
User avatar
Claudio Ricardo
Posts: 367
Joined: Tue Oct 27, 2020 3:38 am
DBs Used: DBF, MySQL, MariaDB
Location: Bs. As. - Argentina

Re: tip_URLEncode + instead of %20

Post by Claudio Ricardo »

Hi, if you need only replace space with "%20", can try:
MsgDebug ( StrTran ( "Microsoft Office", " ", "%20" ) )
Or...
MsgDebug ( StrTran ( Tip_UrlEncode ( "Microsoft Office" ), "+", "%20" ) )
Corrige al sabio y lo harás más sabio, Corrige al necio y lo harás tu enemigo.
WhatsApp / Telegram: +54 911-63016162
trmpluym
Posts: 304
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands

Re: tip_URLEncode + instead of %20

Post by trmpluym »

Hi Claudio,

Thanks for taking the time to answer my question !

In the end my problem was no problem at all because the API can also use the alternative + encoding in stead of the %20 encoding :D

Sorry for bothering !

Theo
Post Reply