Contact Free trial Login

encodeURIComponent

encodeURIComponent(String): String

Escapes certain characters in a URI component using UTF-8 encoding.

There can be only four escape sequences for characters composed of two "surrogate" * characters. encodeURIComponent escapes all characters except the following: alphabetic, decimal digits, - _ . ! ~ * ' ( ). Note that encodeURIComponent differs from encodeURI in that it encodes reserved characters and the Number sign # of encodeURI:

Type Includes

Reserved characters

Unescaped characters

alphabetic, decimal digits, - _ . ! ~ * ' ( )

Number sign

Parameters

Name Description

text

URI component string.

Example

This example encodes a variety of URI components.

Source

%dw 2.0
import * from dw::core::URL
output application/json
---
{
  "comparing_encode_functions_output" : {
  	"encodeURIComponent" : encodeURI(" PATH/ TO /ENCODE "),
  	"encodeURI" : encodeURI(" PATH/ TO /ENCODE "),
  	"encodeURIComponent_to_hex" : encodeURIComponent(";,/?:@&="),
  	"encodeURI_not_to_hex" : encodeURI(";,/?:@&="),
  	"encodeURIComponent_not_encoded" : encodeURIComponent("-_.!~*'()"),
  	"encodeURI_not_encoded" : encodeURI("-_.!~*'()")
  }
}

Output

{
  "comparing_encode_functions_output": {
    "encodeURIComponent": "%20PATH/%20TO%20/ENCODE%20",
    "encodeURI": "%20PATH/%20TO%20/ENCODE%20",
    "encodeURIComponent_to_hex": "%3B%2C%2F%3F%3A%40%26%3D",
    "encodeURI_not_to_hex": ";,/?:@&=",
    "encodeURIComponent_not_encoded": "-_.!~*'()",
    "encodeURI_not_encoded": "-_.!~*'()"
  }
}

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.