Modifier

Partager via


Text.StrLen(Text) Method

Version: Available or changed with runtime version 1.0.

Gets the length of a string you define.

Syntax

Length :=   Text.StrLen(String: Text)

Note

This method can be invoked without specifying the data type name.

Parameters

String
 Type: Text
The string for which you want to determine the length.

Return Value

Length
 Type: Integer
The length of the string.

Remarks

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 Business Central, 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.

Example

This example shows the difference between the StrLen and the MaxStrLen methods.

var
    City: Text[30];
    MaxLength: Integer;
    Length: Integer;
    Text000: Label 'Atlanta';
    Text001: Label 'The MaxStrLen method returns: %1,\\';
    Text002: Label 'whereas the StrLen method returns: %2';
begin
    City := Text000;  
    MaxLength := MaxStrLen(City);  
    Length := StrLen(City);  
    Message(Text001 + Text002, MaxLength, Length);  
end;

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.

Text Data Type
Get Started with AL
Developing Extensions