Changes the length of a string to a length that you define.
NewString := PADSTR(String, Length[, FillCharacter])
- Type: Text constant or code The string that you want to increase or decrease.
- Type: Integer The new length of the output string. If Length is less than the length of String, then String is truncated. Otherwise String is expanded with filler characters. If Length is less than 0, then an error is returned.
- Type: Text constant or code This is a string of length 1. This character is used to fill empty spaces at the end of the output string. If not specified, spaces are used as default. If the length of FillCharacter is not 1, an error is returned.
Property Value/Return Value
Type: Text constant or code
The output string. The length of the return value is Length characters. If the maximum (defined) length of NewString is less than Length, a run-time error occurs.
If you omit FillCharacter and String is shorter than Length, then spaces are added at the end of String to match Length.
If you omit FillCharacter and String is longer than Length, then String is truncated.
This example requires that you create the following variables and text constants in the C/AL Globals window.
|Text constant||ENU value|
Before PADSTR is called:\
>%1< has the length %2\
>%3< has the length %4\
After PADSTR is called:\
Str1 := Text000; Str2 := Text001; Len1 := STRLEN(Str1); Len2 := STRLEN(Str2); MESSAGE(Text002 + Text003 + Text004, Str1, Len1, Str2, Len2); Str1 := PADSTR(Str1, 5); // Truncate the length to 5 Str2 := PADSTR(Str2, 15, 'w'); // Concatenate w until length = 15 Len1 := STRLEN(Str1); Len2 := STRLEN(Str2); MESSAGE(Text005 + Text003 + Text004, Str1, Len1, Str2, Len2);
The first message window displays the following:
Before PADSTR is called:
>13 characters< has the length 13
>Four< has the length 4
The second message window displays the following:
After PADSTR is called:
>13 ch< has the length 5
>Fourwwwwwwwwwww< has the length 15