---
schema_version: "1"
id: 9094f358e1d68b2a58d440c3302ac2d3b79e84802f838c3906630fe15655e534
title: Length()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/string/mc-ampscript-reference-string-length.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-string/mc-ampscript-reference-string-length.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c8c308d8d214eb50bd13da8abebedde26a11f9c61b03c1bbccce3c8b56644073
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# Length()

Returns the number of characters in a string.

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>✅ Yes</td>
  </tr>
</table>

This function became available in Marketing Cloud Next during the Summer ’26 release (API version 67.0).

## Syntax

```
Length(sourceString)
```

The `Length` function has one parameter:

- `sourceString` (string): Required. The string that you want to find the length of.

## Usage

To use this function, pass it a string. This example uses the `Length()` function to determine if the length of a URL exceeds a certain threshold. If it does, then the function passes the URL to the [WrapLongUrl() function](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/fun_http/mc-ampscript-reference-http-wrap-long-url.md) to obtain a shortened URL. Otherwise, the function uses the original URL.

```
%%[
  Var @imageUrl, @imageUrlLength
  /* A very long string that contains 1200 characters */
  Set @imageUrl = "https://cdn.example.com/images/0800fc577294c34...e0b28ad2839435945/28ad2839435945.png"
  Set @imageUrlLength = Length(@imageUrl)

  If @imageUrlLength >= 975 then
]%%

<img src="%%=WrapLongUrl(@imageUrl)=%%" />

%%[ Else ]%%

<img src="%%=v(@imageUrl)=%%" />

%%[ EndIf ]%%
```

The example outputs an image with a `src` URL that varies based on the length of the source URL.
