---
schema_version: "1"
id: 7153cf9443bed47135b94001fc7c8a82effedeebd3e7ff77322b0f56d936d4f3
title: "Handlebars Helper Function: stringToHex"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/string/mcn-handlebars-reference-string-stringtohex.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-string-references/mcn-handlebars-reference-string-stringtohex.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 1693ec1bb8a51257340ce7e6405ee3aeaf8e80898f65ba9cc693b9da4ee5f052
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# 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

```handlebars
{{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.

```handlebars
{{stringToHex "Hello world!"}}
```

The function returns:

```text
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.

```handlebars
{{stringToHex "Hello world!" charSet="UTF-16"}}
```

The function returns:

```text
480065006c006c006f00200077006f0072006c0064002100
```
