Rexx Programming/How to Rexx/case conversion

From Wikibooks, open books for an open world
Jump to navigation Jump to search

The rexx scripting language does not provide dedicated functions for converting strings to uppercase or to lowercase. However, there are solutions available:

Converting a string to uppercase[edit]

If the translate function is used with only one argument is used, it will convert all alphabetical characters in a string to uppercase:

mystring="I want to go to the BIG APPLE"
ustring = translate(mystring)
say ustring

Converting a string to lowercase[edit]

Conversion to lowercase lettering is a bit more tricky, because there is no dedicated inbuilt function for lowercase conversion. In order to translate a string into lowercase, it is necessary to provide a set of uppercase and lowercase letters, and use the translate function to perform conversion:

upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower = 'abcdefghijklmnopqrstuvwxyz'
mystring="I want to go to the BIG APPLE"
lstring = translate(mystring, lower, upper)
say lstring

Converting a string using PIPE[edit]

If the PIPE commands are available, there is a stage called XLATE which can provide case conversion.

name = 'eric'
'PIPE VAR name | XLATE UPPER | VAR name'
SAY name                                            Shows 'ERIC'
name = 'ERIC'
'PIPE VAR name | XLATE LOWER | VAR name'
SAY name                                            Shows 'eric'
name = 'eric'
'PIPE VAR name | XLATE 1 UPPER | VAR name'
SAY name                                            Shows 'Eric'
name = 'ERIC'
'PIPE VAR name | XLATE 2-4 LOWER | VAR name'
SAY name                                            Shows 'Eric'