Length Function

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.



1 = String value to evaluate the length of characters (can be a variable)




var @string 
set @string = “AMPSCRIPT.COM”
set @lengthString = Length(@string)
Output: %%=v(@lengthString)=%%



Output: 13


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.

Leave a Reply

Your email address will not be published. Required fields are marked *