RosettaCodeData/Task/String-case/REXX/string-case-5.rexx

19 lines
1.5 KiB
Rexx
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
/*REXX program capitalizes each word in string, and maintains imbedded blanks. */
2013-04-11 01:07:29 -07:00
x= "alef bet gimel dalet he vav zayin het tet yod kaf lamed mem nun samekh",
2016-12-05 22:15:40 +01:00
"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.*/
2013-04-11 01:07:29 -07:00
2016-12-05 22:15:40 +01:00
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*/
2013-04-11 01:07:29 -07:00
2016-12-05 22:15:40 +01:00
return substr($, 2) /*return the capitalized words. */