Sunday, July 9, 2017

REXX: Built in Text Functions

They are many type of functions available in REXX. In this post, we will get in details of Text Functions.

Text functions interrogate or manipulate specific text within a character string.


  • Abbrev - Used to test for the text and length of abbreviations. Returns either a 1 or 0. 
  • Space   - Format a given line with a specified number of pad characters between each word in the line. 
  • Translate - Translates characters to uppercase or other characters. 

ABBREV:

This function compares the first length characters of information to info and returns 1 (true) if they match exactly including case. Otherwise, 0(false) is returned.

Syntax:  ABBREV(information,info,length(optional)

Example:

ABBREV('TEST','TES')             /*returns 1*/
ABBREV('TEST','tes')               /*returns 0*/  
ABBREV('TEST','TE',3)           /*returns 0 */        
ABBREV('TEST','')                  /*returns 1*/

the default for length is the number of characters in info.

SPACE:

This function replaces all spaces in between each word in a string with the pad characters for the specified n value. Leading and trailing spaces are always removed. 

The default for n is 1 and the default for pad is space. 

Syntax: SPACE(string, n, pad)

Example:
SPACE(' I am a hero ')          /*'I am a hero'*/
SPACE('I am a hero ',2,'*')   /*'I**am**a**hero'*/
SPACE('I am a hero',0,'*')    /*'Iamahero*/ 
SPACE('I am a hero','','*')     /*'I*am*a*hero*/

TRANSLATE:

This functions does translate each character in the string according the character map that is defined. If no character mapping is done, then only the string is translated to uppercase. 

Syntax: TRANSLATE(string,replace string, search string, pad)

Example:
TRANSLATE("AbendMaker")              /*returns 'ABENDMAKER'  */
TRANSLATE("Abend",'1','A')               /*returns '1bend'   */
TRANSLATE("Abend",'1','Ab')             /*returns '1 end'    */

TRANSLATE("Abend",'1','Ab','*')        /*returns '1*end'   */
TRANSLATE("Abend",'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')                                                                /*returns 'abend'   */
TRANSLATE("Abend",xrange('a','z'),xrange('A','Z')        /*returns 'abend'   */

If only input string is provided, all the alpha characters would be converted to Uppercase.
TRANSLATE converts only the string to uppercase and their is no lowercase conversion option. In order to convert to lowercase, the last two examples shall be used using the TRANSLATE function. 

When the replace string has fewer characters than the search string, the later characters of search string will be replaced with spaces or if specified with pad characters. 

No comments:

Post a Comment

Featured Post

REXX Skeleton: Submitting jobs through Rexx

Submitting jobs through REXX and reading the spool through REXX gives us immense potential to automate many manual activities in mainframes....