Handlebars Helper Function: stringToHex

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 

1{{stringToHex sourceString [charSet=CHARSET]}}

Parameters 

ParameterTypeDescription
sourceStringStringRequired. The string to convert.
charSetStringThe 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.

1{{stringToHex "Hello world!"}}

The function returns:

148656c6c6f20776f726c6421

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.

1{{stringToHex "Hello world!" charSet="UTF-16"}}

The function returns:

1480065006c006c006f00200077006f0072006c0064002100