# Eliminating Double Spaces in alpha

**URL:** <https://techcommunity.softwareag.com/t/eliminating-double-spaces-in-alpha/204752>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Linux\
**Created:** [July 23, 2019, 6:12pm UTC](https://techcommunity.softwareag.com/t/eliminating-double-spaces-in-alpha/204752 "2019-07-23T18:12:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jared\_Lenos](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jared_lenos/32/1308_2.png) [@Jared\_Lenos](https://techcommunity.softwareag.com/u/Jared_Lenos)\
**Post date:** [July 23, 2019, 6:12pm UTC](https://techcommunity.softwareag.com/t/eliminating-double-spaces-in-alpha/204752/1 "2019-07-23T18:12:56Z")

</div>

I have an (largely) formatting issue that I would like to solve in a neat way if possible.

When using a natural date format, I sometimes want to display it natively as a ‘nice’ date.

I can use the edit-mask properties to do some manipulation on the date format to get it to specific string representations. That is great.

Recently I was asked to present the date in the format ‘Weekday Month DD, YYYY’.

I can do this with:

```auto
 define data local 
01 #date-alpha (a8)
01 #date (d)
01 #date-print (a30)  
end-define

#date-alpha := *datn
move edited #date-alpha to #date(em=yyyymmdd)
move edited #date(EM=N(9)' 'L(10)^DD','^YYYY) to #date-print
print #date-print
end
```

However, when the date is early in the month, the ^DD result appears as ‘08’ which is not pretty.

So I’ve replaced it with

```auto
move edited #date(EM=N(9)' 'L(10)^ZD','^YYYY) to #date-print
```

which now results in the 0 being replaced with a blank character.

Now I’m left with the task of eliminating this character from the string.

```auto
examine #date-print for ' ' replace ' '
```

was my first attempt, however, the double space is simply recognized as a blank string array. Similarly, H’2020’ also resulted in no observable change.  
I could create a more complex set of statements to solve this for this specific case:

```auto
define data local 
01 #date-alpha (a8)
01 #date (d)
01 #date-print (a30)  
01 #pos (i4)
01 #len (i4)
01 #i (i4)
01 #is-space (L)
end-define

#date-alpha := *datn
move edited #date-alpha to #date(em=yyyymmdd)
move edited #date(EM=N(9)' 'L(10)^ZD','^YYYY) to #date-print
examine #date-print for ' ' giving length #len
for #i = 1 to #len
  #pos := #len - #i + 1 
  examine substring(#date-print, #i, #pos) for ' ' giving position #pos
  if #pos = 1
    if #is-space = true
      #pos := #len - #i + 1
      examine substring(#date-print, #i, #pos) for ' ' delete
      examine #date-print for ',2' replace ', 2' /* fix for the year space as it gets caught in the remaining string
    else
      #is-space := true
    end-if
  else
    #is-space := false
  end-if
end-for
print #date-print

end
```

I feel like there should be a universal, simple method to eliminate a double space in a string within Natural. Would anyone care to elaborate? Maybe a simpler version of the per-character for loop which spits each element into a new string only if the previous one wasn’t a space?

Thanks!

---

<div class="post-metadata">

**Author:** ![Chad\_Scott](https://avatars.discourse-cdn.com/v4/letter/c/b3f665/32.png) [@Chad\_Scott](https://techcommunity.softwareag.com/u/Chad_Scott)\
**Post date:** [July 23, 2019, 6:47pm UTC](https://techcommunity.softwareag.com/t/eliminating-double-spaces-in-alpha/204752/2 "2019-07-23T18:47:27Z")

</div>

What you were using to eliminate the double space is close, just need to use the FULL option:  
EXAMINE #DATE-PRINT for FULL ’ ’ replace ’ ’

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [July 25, 2019, 11:30am UTC](https://techcommunity.softwareag.com/t/eliminating-double-spaces-in-alpha/204752/3 "2019-07-25T11:30:26Z")

</div>

An additional statement EXAMINE … REPLACE … is not necessary, when you use an appropriate EM depending on whether there is a leading 0 in the day number.

```auto
DEFINE DATA LOCAL                                                  
01 #DATE-ALPHA (A8)                                   
01 REDEFINE #DATE-ALPHA                                            
  02 #YYYYMM (A6)                                   
  02 #D1 (N1) /* is the value 0 ?                               
  02 #D2 (A1)                                   
01 #DATE (D)                                    
01 #DATE-PRINT (A30)                                  
END-DEFINE                                                         
*                                                                  
#DATE-ALPHA := '20190509'                                          
MOVE EDITED #DATE-ALPHA TO #DATE(EM=YYYYMMDD)                      
*                                                                  
IF #D1 NE 0                                                        
  MOVE EDITED #DATE(EM=N(9)' 'L(10)^DD','^YYYY) TO #DATE-PRINT     
ELSE                                                               
  MOVE EDITED #DATE(EM=N(9)' 'L(10)ZD','^YYYY) TO #DATE-PRINT     
END-IF                                                             
PRINT #DATE-PRINT                                                  
END                                                                
```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 3:43pm UTC](https://techcommunity.softwareag.com/t/eliminating-double-spaces-in-alpha/204752/4 "2021-04-02T15:43:11Z")

</div>


