# Compress Array of strings

**URL:** <https://clarionhub.com/t/compress-array-of-strings/7407>\
**Category:** questions\
**Tags:** language\
**Created:** [August 21, 2024, 5:15am UTC](https://clarionhub.com/t/compress-array-of-strings/7407 "2024-08-21T05:15:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niels\_Larsen](https://clarionhub.com/user_avatar/clarionhub.com/niels_larsen/32/655_2.png) [@Niels\_Larsen](https://clarionhub.com/u/Niels_Larsen)\
**Post date:** [August 21, 2024, 5:15am UTC](https://clarionhub.com/t/compress-array-of-strings/7407/1 "2024-08-21T05:15:09Z")

</div>

Hi  
I have a 1 dimensional array of strings. The size can be dim(xxx). I would like to create a procedure that takes my array as a parameter to subsequently remove all empty strings and move the strings together, and return it - preferably as a pointer.  
Can this be done in Clarion?

/Niels

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 21, 2024, 6:09am UTC](https://clarionhub.com/t/compress-array-of-strings/7407/2 "2024-08-21T06:09:01Z")

</div>

☹ se a LOOP. I’m on my phone so this may not be perfect

```auto
StringArrayCompress PROCEDURE(*STRING[] Str),LONG,PROC
N LONG 
T LONG ! Out index 
  Code
  LOOP N=1 TO MAXIMUM(Str[],1)
!Wrong: IF Str[N] THEN CYCLE. Leaves only blanks :(
    IF Str[N] = '' THEN CYCLE.
    T += 1
    IF T = N THEN CYCLE. 
    Str[T] = Str[N]
    Str[N] = ''
  END
  RETURN T  
  ! Return how many found, PROC makes optional

```

Example

```auto
Addr STRING(50),DIM(5)
...
  Addr[1]=Vendor:Address1
   ... [2]=2 ... 3 ... 4
  Addr[5]=Clip(City) & Clip(' '&State) & Clip(' '&Zip)
  IF StringArrayCompress(Addr[]) >= 5 THEN
     ! Print 5 line address smaller
  ELSE
     ! Print bigger if 4 or less lines

```

---

<div class="post-metadata">

**Author:** ![Niels\_Larsen](https://clarionhub.com/user_avatar/clarionhub.com/niels_larsen/32/655_2.png) [@Niels\_Larsen](https://clarionhub.com/u/Niels_Larsen)\
**Post date:** [August 21, 2024, 6:28am UTC](https://clarionhub.com/t/compress-array-of-strings/7407/3 "2024-08-21T06:28:38Z")

</div>

Well, as done on a phone it’s pretty impressive. But at first glance it makes good sense. I try.  
THANKS

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [August 21, 2024, 7:34am UTC](https://clarionhub.com/t/compress-array-of-strings/7407/4 "2024-08-21T07:34:57Z")

</div>

> [@Niels\_Larsen](#):
>
> Well, as done on a phone it’s pretty impressive

Agree. Good work Carl.

I am also on my phone waiting in my car but I think the line at the top of the loop with the cycle should have a not on the condition.

`IF not Str[N] THEN CYCLE.`

Or alternatively

`IF Str[N] = '' THEN CYCLE.`

Cheers

Geoff R

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [August 21, 2024, 12:30pm UTC](https://clarionhub.com/t/compress-array-of-strings/7407/5 "2024-08-21T12:30:20Z")

</div>

> [@vitesse](#):
>
> IF not Str[N] THEN CYCLE.

Dang, I had it `IF ~` then “tried” to change to `IF ... =' ' ` but forgot some
