Runtime verified Differs from official docs Test scripts included

Syntax

Char(characterCode[, numRepetitions])  →  string
1–2 arguments

Parameters

Name Type Required Description
characterCode string | number Yes Character code, as a whole number
numRepetitions string | number No Number of times to repeat the returned character, as a whole number

Only codes from 0 to 255 render in Next — see below.

Example

%%=Char(65)=%%

Renders A.

The second argument repeats the character:

%%=Char(65, 3)=%%

Renders AAA.

Return value

string — the character for the code, repeated when a count is given.

A count of 0 gives an empty string. Beyond that there is no fixed set of special values to test for.

Behaviour

Codes 0 to 255 give their Latin-1 character. Char(64) gives @, Char(34) a double quote, Char(39) an apostrophe, and Char(190), Char(233) and Char(255) give ¾, é and ÿ. Each measures Length 1.

Control codes come back as one character each. Char(9) is a tab, Char(10) a line feed, Char(13) a carriage return and Char(32) a space. Char(0) returns the NUL character, which measures Length 1. These are invisible in the rendered email, so measure them rather than looking for them.

The repeat count. Char(65,3) gives AAA, Char(65,1) gives A, and Char(65,0) gives an empty string (Length 0).

Numeric strings work in both positions. Char("65") gives A and Char(65,"3") gives AAA.

Any code outside 0 to 255 breaks the preview. An email with Char(256), Char(8364), Char(9731), Char(65601), Char(128512) or Char(-1) saves, but rendering it fails with HTTP 500. Wrapping the call in Length does not help.

Invalid arguments break the preview too. A decimal code (Char(65.7)), a non-numeric string (Char("A")), a boolean (Char(true)), a negative count (Char(65,-1)) and a decimal count (Char(65,2.6)) each save, but the email does not render. There is no error value to test for, so check the arguments before the call.

No arguments or three arguments cannot be saved. Char() and Char(65,2,1) are rejected at save with HTTP 400 “The AMPscript syntax isn’t valid”.

Show Next test script
<!-- Marketing Cloud Next test script for Char. Paste it into the HTML component of a
     Next email and open the preview. Each line prints the result Next gave when the call
     was rendered on its own (expect) next to the result of this run (got).
     Assembled from single-call test emails (dates on the page); it has not been
     run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[A] got=[%%=Char(65)=%%]</p>
<p>c2 expect=[@] got=[%%=Char(64)=%%]</p>
<p>c3 expect=[AAA] got=[%%=Char(65,3)=%%]</p>
<p>c4 expect=[A] got=[%%=Char("65")=%%]</p>
<p>c5 expect=["] got=[%%=Char(34)=%%]</p>
<p>c6 expect=['] got=[%%=Char(39)=%%]</p>
<p>c7 expect=[A] got=[%%=Char(65,1)=%%]</p>
<p>c8 expect=[¾] got=[%%=Char(190)=%%]</p>
<p>c9 expect=[é] got=[%%=Char(233)=%%]</p>
<p>c10 expect=[ÿ] got=[%%=Char(255)=%%]</p>
<p>c11 expect=[	] got=[%%=Char(9)=%%]</p>
<p>c12 expect=[U+000A] got=[%%=Char(10)=%%]</p>
<p>c13 expect=[U+000D] got=[%%=Char(13)=%%]</p>
<p>c14 expect=[ ] got=[%%=Char(32)=%%]</p>
<p>c15 expect=[U+0000] got=[%%=Char(0)=%%]</p>
<p>c16 expect=[1] got=[%%=Length(Char(0))=%%]</p>
<p>c17 expect=[AAA] got=[%%=Char(65,"3")=%%]</p>
<p>c18 expect=[] got=[%%=Char(65,0)=%%]</p>
<p>c19 expect=[0] got=[%%=Length(Char(65,0))=%%]</p>
<p>c20 expect=[1] got=[%%=Length(Char(65))=%%]</p>
<p>c21 expect=[1] got=[%%=Length(Char(190))=%%]</p>
<p>c22 expect=[1] got=[%%=Length(Char(255))=%%]</p>
<p>c23 expect=[3] got=[%%=Length(Char(65,3))=%%]</p>

Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
     would stop the whole preview or block the save. -->

<!-- email 1: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(256)=%%

<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(8364)=%%

<!-- email 3: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(-1)=%%

<!-- email 4: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(65601)=%%

<!-- email 5: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(Char(65601))=%%

<!-- email 6: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(128512)=%%

<!-- email 7: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(Char(128512))=%%

<!-- email 8: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(9731)=%%

<!-- email 9: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(Char(9731))=%%

<!-- email 10: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(Char(256))=%%

<!-- email 11: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(65.7)=%%

<!-- email 12: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char("A")=%%

<!-- email 13: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(true)=%%

<!-- email 14: expect that the email saves, but the preview never shows the new version (no fresh render) -->
%%=Char(65, -1)=%%

<!-- email 15: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Char(65, 2.6)=%%

<!-- email 16: expect that the save is rejected (HTTP 400) -->
%%=Char()=%%

<!-- email 17: expect that the save is rejected (HTTP 400) -->
%%=Char(65, 2, 1)=%%

Differs from official docs

  • Char works in Next. The reference lists Char as not available in Marketing Cloud Next. A Next email rendered Char(65) as A and Char(65,3) as AAA; only codes outside 0 to 255 fail. Card

Availability & differences

PlatformAvailable
Marketing Cloud EngagementYes
Marketing Cloud NextYes, from API 68.0

See also