URLENCODE function

URLENCODE is a string manipulation function that manipulates CHARACTER string data.

Syntax

Read syntax diagramSkip visual syntax diagramURLENCODE( SourceExpressionMODERFC3986RFC1798 )

URLENCODE returns a CHARACTER string that contains the source string in which the characters are not interpreted as special characters within a URL.

RFC3986 encoding is used by default.

If the URLENCODE function uses RCF3986, the source string is copied into the UTF-8 code page and each byte is replaced by a % (percent) symbol followed by the 2 hexadecimal digits that represent the replaced character's value. The following characters are not replaced:
  • - (hyphen)
  • _ (underscore)
  • . (period)
  • ~ (tilde)
  • alphanumeric characters

If the URLENCODE function uses RCF1738, it operates similarly to if it uses RCF3986 except that the ~ (tilde) character is replaced by it's hexadecimal value and a space is replaced by the + (plus) symbol.

Use the URLDECODE function to decode an encoded string to it's original form.

An example that uses RCF3986:

DECLARE original CHARACTER 'Name=John Smith/Address=Hampshire~United Kingdom/Telephone=+441962808000/';
    DECLARE encoded CHARACTER URLENCODE(original);

results in the following encoded string:

Name%3DJohn%20Smith%2FAddress%3DHampshire~United%20Kingdom%2FTelephone%3D%2B441962808000%2F'

An example that uses RCF1738:

DECLARE original CHARACTER 'Name=John Smith/Address=Hampshire~United Kingdom/Telephone=+441962808000/';
	DECLARE encoded CHARACTER URLENCODE(original MODE RFC1738);

results in the following encoded string:

Name%3DJohn+Smith%2FAddress%3DHampshire%7EUnited+Kingdom%2FTelephone%3D%2B441962818000%2F'