STRLEN Function (Code, Text)
Returns the length of a string you define.
Length := STRLEN(String)
Parameters
- String
-
Type: Text constant or code
The string for which you want to determine the length.
The difference between the STRLEN function and the MAXSTRLEN Function (Code, Text) is that the STRLEN returns the actual number of characters in the input string, while MAXSTRLEN returns the maximum defined length of the input string.
If you call STRLEN on a Variant, 0 is returned.
This example shows the difference between the STRLEN and the MAXSTRLEN functions. Assume the variable City was defined with a maximum length of 30 characters.
This example requires that you create the following text constants in the C/AL Globals window.
| Text constant | ENU value |
|---|---|
|
Text000 |
'Atlanta' |
|
Text001 |
'The MAXSTRLEN function returns: %1,\' |
|
Text002 |
'while the STRLEN function returns: %2' |
City := Text000; MaxLength := MAXSTRLEN(City) Length := STRLEN(City); MESSAGE(Text001 + Text002, MaxLength, Length);
The message window displays the following:
The MAXSTRLEN function returns: 30
while the STRLEN function returns: 7
This shows that the MAXLENGTH function returns the maximum possible length according to the definition of the string variable, while STRLEN returns the actual length of the text.