# System.CompressArray(Array of [Text]) Method
> Version: _Available or changed with runtime version 1.0._
Moves all non-empty strings (text) in an array to the beginning of the array. The resulting StringArray has the same number of elements as the input array, but empty entries appear at the end of the array.
## Syntax
```al
[Count := ]  System.CompressArray(StringArray: Array of [Text])
```
> NOTE
> This method can be invoked without specifying the data type name.
## Parameters
StringArray
Type: ../text/text-data-type
The string array that you want to compress.
## Return Value
*[Optional] Count*
Type: ../integer/integer-data-type
## Remarks
When compressing an array of strings, the non-empty strings in the resulting array are sorted just like in the original array.
The CompressArray method is useful for printing names and addresses. For instance, you can use this method to remove blank lines in account statements.
This method compresses an array of Text or Code, but not BigText. The compression is performed by moving empty strings to the end of the array.
For example, "Redmond", "Copenhagen", "", "Fargo", "Paris" is changed to "Redmond", "Copenhagen", "Fargo", "Paris", "".
In Dynamics 365 Business Central, it is not supported to use the CompressArray method on multidimensional arrays. In earlier versions, CompressArray works for arrays of arrays.
## Example
This example shows how to use the CompressArray method. The input array has the following values: Joe Raybon, One Meca Way, Atlanta.
The output StringArray has the following values: Joe Raybon, One Meca Way, Atlanta.
All non-empty entries have been moved to the beginning of the array.
```al
var
    CustomerData: array[6] of Text;
begin
    CustomerData[1] := 'Joe Raybon';
    CustomerData[2] := ''; // Empty string.
    CustomerData[3] :='One Meca Way';
    CustomerData[4] := '  '; // A non-empty string that contains blanks.
    CustomerData[5] := 'Atlanta';
    CustomerData[6] := ''; // Empty string.
    Message('Before compression the address is: \%1\%2\%3\%4\%5\%6', CustomerData[1], CustomerData[2], CustomerData[3], CustomerData[4], CustomerData[5], CustomerData[6]);
    CompressArray(CustomerData); // The empty lines (strings) are removed.
    Message('After compression the address is: \%1\%2\%3\%4\%5\%6', CustomerData[1], CustomerData[2], CustomerData[3], CustomerData[4], CustomerData[5], CustomerData[6]);
end;
```
The first message window displays the following:
Before compression, the address is:
Joe Raybon
One Meca Way
Atlanta
The second message window displays the following:
After compression, the address is:
Joe Raybon
One Meca Way
Atlanta
All empty strings, which cause blank lines, are moved to the end of the array.
> NOTE
> Empty lines are not printed if they occur on the first or last line in a message window.
## Related information
system-data-type
Get Started with AL<../../devenv-get-started>
Developing Extensions<../../devenv-dev-overview>

Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-compressarray-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact. https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-compressarray-method/
