- 2 minutes to read

Formula - convert

The convert Formula function returns content re-encoded from a source character encoding to a target character encoding.

Syntax

convert('source encoding', 'target encoding', content)

Parameters

Parameter Required Description
'source encoding' Yes The character encoding the content is in, such as 'UTF-8'.
'target encoding' Yes The character encoding to convert to, such as 'iso-8859-1' or 'windows-1252'.
content Yes The text to convert: body, context, or the result of another function.

Returns

The content in the target encoding. When the content holds several values, each value is converted. When the content has no value, nothing is returned.

Examples

The examples pass the converted content to base64encode with the target encoding, so the result shows the bytes that legacy systems expecting the target encoding receive.

Example 1: Prepare UTF-8 text as ISO-8859-1 base64

Input

Skellefteå

Formula

base64encode(convert('UTF-8','ISO-8859-1', body),'ISO-8859-1')

Result

U2tlbGxlZnRl5Q==

Test Expression tab: base64encode of convert UTF-8 to ISO-8859-1 returns U2tlbGxlZnRl5Q== for Skellefteå
In ISO-8859-1, å is the single byte E5, which ends the base64 result in 5Q==.

Example 2: Prepare UTF-8 text as Windows-1252 base64

Input

Café

Formula

base64encode(convert('UTF-8', 'windows-1252', body), 'windows-1252')

Result

Q2Fm6Q==

Test Expression tab: base64encode of convert UTF-8 to windows-1252 returns Q2Fm6Q== for Café
In Windows-1252, é is the single byte E9, which gives 6Q== at the end of the result.

Example 3: Convert a context property

Input

Key Value
CityName Malmö

Formula

base64encode(convert('UTF-8', 'iso-8859-1', context('CityName')), 'iso-8859-1')

Result

TWFsbfY=

Test Expression tab: base64encode of convert UTF-8 to iso-8859-1 on the context property CityName returns TWFsbfY=
The context value Malmö becomes TWFsbfY=; ö is the single byte F6 in ISO-8859-1.

Notes

  • For text like the inputs above, base64encode with an input encoding alone gives the same result: base64encode(body, 'iso-8859-1') also returns U2tlbGxlZnRl5Q== for Skellefteå (see base64encode).
  • If characters already look wrong in the Message Body tab, the body was read with another encoding before any formula ran. See Test in the Wizard with the Right Encoding and Character Encoding for how Nodinite picks the encoding of the body.
  • Encoding names follow .NET; see the List of encodings.

Next Steps