The Length function returns the number of characters in the string. A good use case for it is that it can be used in conjunction with Substring to take the last 4 characters of a phone number. This can also be accomplished using the RegExMatch function. The length function counts all characters including space and symbols.
Syntax:
Length(1)
1 = String value to evaluate the length of characters (can be a variable)
Example:
%%[
var @string
set @string = “AMPSCRIPT.COM”
set @lengthString = Length(@string)
]%%
Output: %%=v(@lengthString)=%%
Output:
Output: 13
Explanation:
The Length function takes the AMPSCRIPT.COM
string counts all the characters in the string including the .
(period). This function is helpful when used in conjunction with other functions or to determine the maximum length of a field value.