# Code Snippet #2 & #3

**URL:** <https://techcommunity.softwareag.com/t/code-snippet-2-3/91472>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples\
**Created:** [October 5, 2009, 9:54am UTC](https://techcommunity.softwareag.com/t/code-snippet-2-3/91472 "2009-10-05T09:54:58Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [October 5, 2009, 9:54am UTC](https://techcommunity.softwareag.com/t/code-snippet-2-3/91472/1 "2009-10-05T09:54:58Z")

</div>

Convert multiple spaces to a single space in any alpha:  
0010 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
0020 \* Copycode : Z1SPACE  
0030 \* Function : Will convert all multiple spaces to a single space  
0040 \* Usage :  
0050 \* INCLUDE Z1SPACE ‘#MY-STRING’  
0060 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
0070 \*  
0080 EXAMINE &1& FOR ’ ’ WITH DELIMITER ’ ’ DELETE  
0090 EXAMINE &1& FOR FULL ’ ’ REPLACE ’ ’

and:

Copycode ZCENTREC  
0010 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
0020 \* Copycode : ZCENTREC  
0030 \*  
0040 \* Desc : This copycode will centre any alpha field contents  
0050 \*  
0060 \* Usage :  
0070 \*  
0080 \* DEFINE DATA LOCAL  
0090 \* 1 #MY-TEXT (A50)  
0100 \* END-DEFINE  
0110 \* #MY-TEXT := ‘THIS IS CENTRED’  
0120 \* INCLUDE ZCENTREC ‘#MY-TEXT’  
0130 \* WRITE #MY-TEXT  
0140 \* END  
0150 \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
0160 \*  
0170 MOVE RIGHT &1& TO &1&  
0180 EXAMINE &1& FOR FULL ’ ’ REPLACE ’ ’  
NOTE: If your text has double spaces the centring will remove them

---

<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, 2:57pm UTC](https://techcommunity.softwareag.com/t/code-snippet-2-3/91472/2 "2021-04-02T14:57:36Z")

</div>


