AMPscript Length (Next)
Measure a string with AMPscript Length in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including the UTF-16 counting unit and the number argument that fails there.
Syntax
Length(sourceString) → number
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
sourceString |
string | date | Yes | Value to measure |
A number or boolean argument saves but makes the email fail to render — see below.
Example
%%=Length("Hello")=%%
Renders 5.
An empty string measures zero:
%%=Length("")=%%
Renders 0.
Return value
number — the count of UTF-16 code units in the value.
Every successful call rendered a plain non-negative whole number. There is no fixed set of special values.
Behaviour
Plain ASCII counts one per character. Length("Hello World") gives 11 and Length("abcd") gives 4.
The unit is the UTF-16 code unit. Length("café") gives 4 and Length("Straße") gives 6, because each of those letters is one code unit. A single emoji such as 😀 gives 2: it is one visible character but two code units. A character limit enforced with Length therefore allows one character fewer for each emoji.
Dates are measured as text. Length(Now()) gave 19, the length of a value like 2026-11-23T00:21:32.
Numbers and booleans break the preview. An email with Length(12345) or Length(true) saves, but rendering it fails with HTTP 500. Measure numbers as text by passing them as a string.
No argument or two arguments cannot be saved. Length() and Length("a", "b") are rejected at save with HTTP 400 “The AMPscript syntax isn’t valid”.
Show Next test script
<!-- Marketing Cloud Next test script for Length. 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=[5] got=[%%=Length("abcde")=%%]</p>
<p>c2 expect=[0] got=[%%=Length("")=%%]</p>
<p>c3 expect=[5] got=[%%=Length("Hello")=%%]</p>
<p>c4 expect=[11] got=[%%=Length("Hello World")=%%]</p>
<p>c5 expect=[4] got=[%%=Length("abcd")=%%]</p>
<p>c6 expect=[4] got=[%%=Length("café")=%%]</p>
<p>c7 expect=[6] got=[%%=Length("Straße")=%%]</p>
<p>c8 expect=[2] got=[%%=Length("😀")=%%]</p>
<p>c9 expect=[19] got=[%%=Length(Now())=%%]</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) -->
%%=Length(12345)=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Length(true)=%%
<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=Length()=%%
<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=Length("a", "b")=%%
Differs from official docs
- The unit is the UTF-16 code unit. The reference does not name a unit; in Next
Length("😀")is2. Card - Numbers and booleans break the render. The reference does not rule them out, but
Length(12345)andLength(true)made the Next preview fail with HTTP 500. Card
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 67.0 |
Text and dates measure the same on both, in UTF-16 code units (an emoji counts as 2). Engagement measures a number by its text (Length(12345) gives 5) and returns 0 for a boolean; in Next both make the email preview fail. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
Concat— builds the string you are measuringUppercase— in Next the sharp s expands when uppercased, so the length growsIndexOf— positions use the same counting unit- Official reference