How to resolve the algorithm String case step by step in the REXX programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm String case step by step in the REXX programming language
Table of Contents
Problem Statement
Take the string alphaBETA and demonstrate how to convert it to:
Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. Note: In some languages alphabets toLower and toUpper is not reversable. Show any additional case conversion functions (e.g. swapping case, capitalizing the first letter, etc.) that may be included in the library of your language.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm String case step by step in the REXX programming language
Source code in the rexx programming language
abc = "abcdefghijklmnopqrstuvwxyz" /*define all lowercase Latin letters.*/
abcU = translate(abc) /* " " uppercase " " */
x = 'alphaBETA' /*define a string to a REXX variable. */
y = translate(x) /*uppercase X and store it ───► Y */
z = translate(x, abc, abcU) /*translate uppercase──►lowercase chars*/
x = "alphaBETA" /*define a string to a REXX variable. */
parse upper var x y /*uppercase X and store it ───► Y */
parse lower var x z /*lowercase X " " " ───► Z */
/*Some REXXes don't support the LOWER option for the PARSE command.*/
x = 'alphaBETA' /*define a string to a REXX variable. */
y = upper(x) /*uppercase X and store it ───► Y */
z = lower(x) /*lowercase X " " " ───► Z */
/*Some REXXes don't support the UPPER and LOWER BIFs (built-in functions).*/
x = "alphaBETA" /*define a string to a REXX variable. */
y=x; upper y /*uppercase X and store it ───► Y */
parse lower var x z /*lowercase Y " " " ───► Z */
/*Some REXXes don't support the LOWER option for the PARSE command.*/
/*REXX program capitalizes each word in string, and maintains imbedded blanks. */
x= "alef bet gimel dalet he vav zayin het tet yod kaf lamed mem nun samekh",
"ayin pe tzadi qof resh shin tav." /*the "old" spelling of Hebrew letters.*/
y= capitalize(x) /*capitalize each word in the string. */
say x /*display the original string of words.*/
say y /* " " capitalized words.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
capitalize: procedure; parse arg z; $=' 'z /*prefix $ string with a blank. */
abc = "abcdefghijklmnopqrstuvwxyz" /*define all Latin lowercase letters.*/
do j=1 for 26 /*process each letter in the alphabet. */
_=' 'substr(abc,j,1); _U=_ /*get a lowercase (Latin) letter. */
upper _U /* " " uppercase " " */
$=changestr(_, $, _U) /*maybe capitalize some word(s). */
end /*j*/
return substr($, 2) /*return the capitalized words. */
/*REXX program swaps the letter case of a string: lower ──► upper & upper ──► lower.*/
abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase letters. */
abcU = translate(abc) /* " " " uppercase " */
x = 'alphaBETA' /*define a string to a REXX variable. */
y = translate(x, abc || abcU, abcU || abc) /*swap case of X and store it ───► Y */
say x
say y
/*stick a fork in it, we're all done. */
x='alphaBETA'; Say ' x='||x
Say 'three ways to uppercase'
u1=translate(x); Say ' u1='u1
u2=upper(x); Say ' u2='u2
parse upper var x u3; Say ' u3='u3
abc ='abcdefghijklmnopqrstuvwxyz'
abcu=translate(abc); Say 'three ways to lowercase'
l1=translate(x,abc,abcu); Say ' l1='l1
l2=lower(x); Say ' l2='l2
parse lower var x l3; Say ' l3='l3
uppercase: /*courtesy Gerard Schildberger */
return translate(changestr("ß",translate(arg(1),'ÄÖÜ',"äöü"),'SS'))
uppercase2: Procedure
Parse Arg a
a=translate(arg(1),'ÄÖÜ',"äöü") /* translate lowercase umlaute */
a=changestr("ß",a,'SS') /* replace ß with SS */
return translate(a) /* translate lowercase letters */
You may also check:How to resolve the algorithm Loops/For step by step in the SPL programming language
You may also check:How to resolve the algorithm Chowla numbers step by step in the Racket programming language
You may also check:How to resolve the algorithm Ascending primes step by step in the Perl programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the Wren programming language