{"title":"System.CompressArray(Array of [Text]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-compressarray-method/","by":"JOP-AL","license":"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.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-compressarray-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Moves all non-empty strings (text) in an array to the beginning of the array.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"System.CompressArray(Array of [Text]) Method","slug":"systemcompressarrayarray-of-text-method","at":0,"chars":2963},{"level":2,"title":"Syntax","slug":"syntax","at":313,"chars":159},{"level":2,"title":"Parameters","slug":"parameters","at":472,"chars":99},{"level":2,"title":"Return Value","slug":"return-value","at":571,"chars":70},{"level":2,"title":"Remarks","slug":"remarks","at":641,"chars":731},{"level":2,"title":"Example","slug":"example","at":1372,"chars":1457},{"level":2,"title":"Related information","slug":"related-information","at":2829,"chars":134}],"text":"# System.CompressArray(Array of [Text]) Method\n> Version: _Available or changed with runtime version 1.0._\nMoves 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.\n## Syntax\n```al\n[Count := ]  System.CompressArray(StringArray: Array of [Text])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nStringArray\nType: ../text/text-data-type\nThe string array that you want to compress.\n## Return Value\n*[Optional] Count*\nType: ../integer/integer-data-type\n## Remarks\nWhen compressing an array of strings, the non-empty strings in the resulting array are sorted just like in the original array.\nThe CompressArray method is useful for printing names and addresses. For instance, you can use this method to remove blank lines in account statements.\nThis 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.\nFor example, \"Redmond\", \"Copenhagen\", \"\", \"Fargo\", \"Paris\" is changed to \"Redmond\", \"Copenhagen\", \"Fargo\", \"Paris\", \"\".\nIn 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.\n## Example\nThis example shows how to use the CompressArray method. The input array has the following values: Joe Raybon, One Meca Way, Atlanta.\nThe output StringArray has the following values: Joe Raybon, One Meca Way, Atlanta.\nAll non-empty entries have been moved to the beginning of the array.\n```al\nvar\n    CustomerData: array[6] of Text;\nbegin\n    CustomerData[1] := 'Joe Raybon';\n    CustomerData[2] := ''; // Empty string.\n    CustomerData[3] :='One Meca Way';\n    CustomerData[4] := '  '; // A non-empty string that contains blanks.\n    CustomerData[5] := 'Atlanta';\n    CustomerData[6] := ''; // Empty string.\n    Message('Before compression the address is: \\%1\\%2\\%3\\%4\\%5\\%6', CustomerData[1], CustomerData[2], CustomerData[3], CustomerData[4], CustomerData[5], CustomerData[6]);\n    CompressArray(CustomerData); // The empty lines (strings) are removed.\n    Message('After compression the address is: \\%1\\%2\\%3\\%4\\%5\\%6', CustomerData[1], CustomerData[2], CustomerData[3], CustomerData[4], CustomerData[5], CustomerData[6]);\nend;\n```\nThe first message window displays the following:\nBefore compression, the address is:\nJoe Raybon\nOne Meca Way\nAtlanta\nThe second message window displays the following:\nAfter compression, the address is:\nJoe Raybon\nOne Meca Way\nAtlanta\nAll empty strings, which cause blank lines, are moved to the end of the array.\n> NOTE\n> Empty lines are not printed if they occur on the first or last line in a message window.\n## Related information\nsystem-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}