The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.

STRLEN Method (Code, Text)

Gets the length of a string you define.


Length := STRLEN(String)  


Type: Text constant or Code

The string for which you want to determine the length.

Property Value/Return Value

Type: Integer

The length of String.


The difference between the STRLEN method and the MAXSTRLEN Method (Code, Text) is that the STRLEN returns the actual number of characters in the input string, whereas MAXSTRLEN returns the maximum defined length of the input string.

In Dynamics 365 for Finance and Operations, Business edition, if you call STRLEN on a Variant, then you get an error that the contents of the parameter are not valid. In earlier versions of Dynamics 365, if you call STRLEN on a Variant, then 0 is returned.


This example shows the difference between the STRLEN and the MAXSTRLEN methods.

This example requires that you create the following global variables and text constants.

Variable name DataType Length
City Text 30
MaxLength Integer Not applicable
Length Integer Not applicable
Text constant ENU value
Text000 Atlanta
Text001 The MAXSTRLEN method returns: %1,\
Text002 whereas the STRLEN method returns: %2
City := Text000;  
MaxLength := MAXSTRLEN(City);  
Length := STRLEN(City);  
MESSAGE(Text001 + Text002, MaxLength, Length);  

The message window displays the following:

The MAXSTRLEN method returns: 30

whereas the STRLEN method returns: 7

This shows that the MAXLENGTH method returns the maximum possible length according to the definition of the string variable, whereas STRLEN returns the actual length of the text.

See Also

Code Data Type
Text Data Type