Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

COMPRESSARRAY Function

Microsoft Dynamics Nav 2009

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 and entries that contain only blanks appear at the end of the array.


[Count =:] COMPRESSARRAY(StringArray)

Parameters

StringArray

Type: Array of strings

The string array that you want to compress.

Type: Integer

The number of non-empty strings that were compressed.

When compressing an array of strings, the non-empty strings in the resulting array are sorted in the same way as in the original array.

The COMPRESSARRAY function is especially useful for printing names and addresses. For instance, you can use this function to remove blank lines in account statements.

This function compresses an array of Text or Code (not BigText). The compression is done by moving empty strings to the end of the array.

For example, "Redmond", "Copenhagen", "", "Fargo", "Paris" is changed to "Redmond", "Copenhagen", "Fargo", "Paris", "".

In Microsoft Dynamics NAV 2009, it is not supported to use the CompressArray function on multidimensional arrays. In previous versions, CompressArray works for arrays of arrays.

This example shows how to use the COMPRESSARRAY function. The input StringArray 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.

This example requires that you create the following text constants in the C/AL Globals window.

Text constant ENU value

Text000

'Joe Raybon'

Text001

'One Meca Way'

Text002

'Atlanta'

Text003

'Before compression, the address is…\%1\%2\%3\%4\%5\%6'

Text004

'After compression, the address is…\%1\%2\%3\%4\%5\%6'

Name[1] := ''; // Empty String
Name[2] := Text000;
Name[3] := Text001;
Name[4] := ' '; // A string containing blanks
Name[5] := Text002;
Name[6] := '';
MESSAGE(Text003, Name[1], Name[2], Name[3], Name[4], Name[5], Name[6]);
COMPRESSARRAY(Name); // The empty lines (strings) are removed
MESSAGE(Text004, Name[1], Name[2], Name[3],Name[4], Name[5], Name[6]);

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:

Joe Raybon

One Meca Way

Atlanta

All empty and blank strings, which cause blank lines, are moved to the end of the array. The other elements are moved to the beginning of the array.

NoteNote

Empty lines are not printed if they occur on the first or last line in a message window.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.