String case: Difference between revisions

Content deleted Content added
Thundergnat (talk | contribs)
m Move Peloton example to correct position
m →‎{{header|REXX}}: changed/added comments and whitespace, changes some version names, changed indentations.
Line 1,679:
 
=={{header|REXX}}==
===version with TRANSLATE BIF===
The following code will execute correctly in   '''ASCII'''   and   '''EBCDIC.
<lang rexx>abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase Latin letters.*/
abcU = translate(abc) /* " " uppercase " uppercase " */
 
x = 'alphaBETA' /*define a string to a REXX variable. */
y = translate(x) /*uppercase X and store it───►it ───► Y */
z = translate(x, abc, abcU) /*trantranslate uppercase──►lowercase chars*/</lang>
 
===version with PARSE UPPER &amp; PARSE LOWER statements===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<lang rexx>x = "alphaBETA" /*define a string to a REXX variable. */
parse upper var x y /*uppercase X and store it───►it ───► Y */
parse lower var x z /*lowercase X " " " ───► Z */
 
/*Some REXXes don't support the LOWER option for the PARSE command.*/</lang>
 
===version with UPPER &amp; LOWER BIFs===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<lang rexx>x = 'alphaBETA' /*define a string to a REXX variable. */
y = upper(x) /*uppercase X and store it───►it ───► Y */
z = lower(x) /*lowercase X " " " ───► Z */
 
/*Some REXXes don't support the UPPER and LOWER BIFs (built-in functions).*/</lang>
/* LOWER BIFs (built-in functions). */</lang>
 
===version with UPPER statement===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<lang rexx>x = "alphaBETA" /*define a string to a REXX variable. */
y=x; upper y /*uppercase X and store it───►it ───► Y */
parse lower var x z /*lowercase Y " " " ───► Z */
 
/*Some REXXes don't support the LOWER option for the PARSE command.*/</lang>
 
===version with capitalized words===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<lang rexx>/*REXX pgmprogram 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 /*showdisplay the original string of words. */
say y /*show the " " capitalized words. words.*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*───────────────────────────────────CAPITALIZE subroutine──────────────*/
capitalize: procedure; parse arg z; $=' 'z /*prefix $ string with a blank. */
abc = "abcdefghijklmnopqrstuvwxyz" /*define all Latin lowercase letters. */
 
do j=1 for 26 do j=1 for 26 /*process each letter in the alphabet. */
_=' 'substr(abc,j,1); _U=_; upper _U /*get a lower andlowercase upper (Latin) letter. */
$ = changestr(_, $, upper _U) /*maybe capitalize" " uppercase " " some word(s). */
$=changestr(_, $, _U) /*maybe capitalize some word(s). */
end /*j*/
end /*j*/
 
return substr($, 2) /*return the capitalized words,. -1st blank.*/</lang>
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, so one is included here ──► &nbsp; [[CHANGESTR.REX]]. <br>
<br>
Line 1,742:
<br><br>
 
===version with case swap===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<lang rexx>/*REXX pgmprogram swaps the letter case of a string: lower──►upper lower ──► upper & upper──►lower 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. */</lang>
'''output'''
<pre>