Converts each character in a string to its hexadecimal equivalent.
Availability
This helper is available in the Winter ’27 release of Marketing Cloud Next.
Syntax
{{stringToHex sourceString [charSet=CHARSET]}}
Parameters
| Parameter | Type | Description |
|---|---|---|
sourceString |
String | Required. The string to convert. |
charSet |
String | The character set to use. Specify as a named parameter with a value of UTF-8 or UTF-16. The default is UTF-8. |
Return Value
The function returns a hexadecimal string that represents the encoded characters in sourceString.
Usage Example
This example converts a string of text to its UTF-8 hexadecimal representation.
{{stringToHex "Hello world!"}}
The function returns:
48656c6c6f20776f726c6421
This example converts the same string, but specifies UTF-16 encoding. Each character requires more bytes in UTF-16, so the resulting string is longer.
{{stringToHex "Hello world!" charSet="UTF-16"}}
The function returns:
480065006c006c006f00200077006f0072006c0064002100