Converting an uppercase string so that just the first character in each word is uppercase
| Date: | Archived |
|---|---|
| Product/Release: | LANSA - All Platforms |
| Abstract: | RDML code that will convert a string from all uppercase to just having the first character in each word in uppercase. |
| Submitted By: | LANSA Technical Support |
Description:
The following RDML function can be used to convert a string with all uppercase characters to just having the first character in each word in uppercase.
Don't forget its easy to cut and paste this RDML code from here to a LANSA for the AS/400 or LANSA for Windows system.
DEFINE FIELD(#UPPER) TYPE(*CHAR) LENGTH(26)
DEFINE FIELD(#LOWER) TYPE(*CHAR) LENGTH(26) INPUT_ATR(LC)
DEFINE FIELD(#FIRST) TYPE(*CHAR) LENGTH(1)
DEFINE FIELD(#U1) TYPE(*DEC) LENGTH(2) DECIMALS(0)
DEFINE FIELD(#I1) TYPE(*DEC) LENGTH(2) DECIMALS(0)
DEFINE FIELD(#INPUTSTR) TYPE(*CHAR) LENGTH(52) LABEL('Input String')
DESC('Input String')
DEFINE FIELD(#OUTPUTSTR) TYPE(*CHAR) LENGTH(52)
LABEL('Output String') DESC('Output String') INPUT_ATR(LC)
TOT_ENTRY(26) ENTRY_LEN(1)
DEF_ARRAY NAME(#LOW) INDEXES(#U1) OVERLAYING(#LOWER) TYPE(*CHAR)
TOT_ENTRY(26) ENTRY_LEN(1)
DEF_ARRAY NAME(#INP) INDEXES(#I1) OVERLAYING(#INPUTSTR) TYPE(*CHAR)
TOT_ENTRY(52) ENTRY_LEN(1)
DEF_ARRAY NAME(#OUT) INDEXES(#I1) OVERLAYING(#OUTPUTSTR) TYPE(*CHAR)
TOT_ENTRY(52) ENTRY_LEN(1)
CHANGE FIELD(#UPPER) TO(ABCDEFGHIJKLMNOPQRSTUVWXYZ)
CHANGE FIELD(#LOWER) TO('''abcdefghijklmnopqrstuvwxyz''')
BEGIN_LOOP
DISPLAY FIELDS((#INPUTSTR *IN) (#OUTPUTSTR))
EXECUTE SUBROUTINE(CONVERT)
END_LOOP
* *********
SUBROUTINE NAME(CONVERT)
* ********* Initialise output and first character fields
CHANGE FIELD(#OUTPUTSTR) TO(*DEFAULT)
CHANGE FIELD(#FIRST) TO(T)
* ********* Loop through the whole input string
BEGIN_LOOP FROM(1) TO(52) USING(#I1)
IF COND('(#FIRST = T)')
CHANGE FIELD(#OUT#I1) TO(#INP#I1)
CHANGE FIELD(#FIRST) TO(F)
ELSE
IF COND('#INP#I1 *NE *BLANKS')
* ********* Convert character from upper to lower case
USE BUILTIN(SCANSTRING) WITH_ARGS(#UPPER #INP#I1) TO_GET(#U1)
IF COND('#U1 = 0')
* ********* Character not found
CHANGE FIELD(#OUT#I1) TO(#INP#I1)
ELSE
CHANGE FIELD(#OUT#I1) TO(#LOW#U1)
ENDIF
ELSE
* ********* Ignore next char this is a space
CHANGE FIELD(#FIRST) TO(T)
ENDIF
ENDIF
END_LOOP