2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1 +1,13 @@
|
|||
Take the string "alphaBETA", and demonstrate how to convert it to UPPER-CASE and lower-case. Use the default encoding of a string literal or plain ASCII if there is no string literal in your language. 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.
|
||||
;Task:
|
||||
Take the string '''alphaBETA''' and demonstrate how to convert it to:
|
||||
:::* upper-case and
|
||||
:::* lower-case
|
||||
|
||||
<br>
|
||||
Use the default encoding of a string literal or plain ASCII if there is no string literal in your language.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
{{Template:Strings}}
|
||||
<br><br>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
with Ada.Characters.Handling; use Ada.Characters.Handling;
|
||||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Characters.Handling, Ada.Text_IO;
|
||||
use Ada.Characters.Handling, Ada.Text_IO;
|
||||
|
||||
procedure Upper_Case_String is
|
||||
S : String := "alphaBETA";
|
||||
S : constant String := "alphaBETA";
|
||||
begin
|
||||
Put_Line(To_Upper(S));
|
||||
Put_Line(To_Lower(S));
|
||||
Put_Line (To_Upper (S));
|
||||
Put_Line (To_Lower (S));
|
||||
end Upper_Case_String;
|
||||
|
|
|
|||
63
Task/String-case/AppleScript/string-case-1.applescript
Normal file
63
Task/String-case/AppleScript/string-case-1.applescript
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use framework "Foundation"
|
||||
|
||||
-- toUpperCase :: Text -> Text
|
||||
on toUpperCase(str)
|
||||
set ca to current application
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toUpperCase
|
||||
|
||||
-- toLowerCase :: Text -> Text
|
||||
on toLowerCase(str)
|
||||
set ca to current application
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
lowercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toLowerCase
|
||||
|
||||
-- toCapitalized :: Text -> Text
|
||||
on toCapitalized(str)
|
||||
set ca to current application
|
||||
((ca's NSString's stringWithString:(str))'s ¬
|
||||
capitalizedStringWithLocale:(ca's NSLocale's currentLocale())) as text
|
||||
end toCapitalized
|
||||
|
||||
|
||||
-- TEST
|
||||
on run
|
||||
|
||||
-- testCase :: Handler -> String
|
||||
script testCase
|
||||
on lambda(f)
|
||||
mReturn(f)'s lambda("alphaBETA αβγδΕΖΗΘ")
|
||||
end lambda
|
||||
end script
|
||||
|
||||
map(testCase, {toUpperCase, toLowerCase, toCapitalized})
|
||||
|
||||
end run
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS
|
||||
-- map :: (a -> b) -> [a] -> [b]
|
||||
on map(f, xs)
|
||||
tell mReturn(f)
|
||||
set lng to length of xs
|
||||
set lst to {}
|
||||
repeat with i from 1 to lng
|
||||
set end of lst to lambda(item i of xs, i, xs)
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end map
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
1
Task/String-case/AppleScript/string-case-2.applescript
Normal file
1
Task/String-case/AppleScript/string-case-2.applescript
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"ALPHABETA ΑΒΓΔΕΖΗΘ", "alphabeta αβγδεζηθ", "Alphabeta Αβγδεζηθ"}
|
||||
8
Task/String-case/Fortran/string-case-2.f
Normal file
8
Task/String-case/Fortran/string-case-2.f
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
SUBROUTINE UPCASE(TEXT)
|
||||
CHARACTER*(*) TEXT
|
||||
INTEGER I,C
|
||||
DO I = 1,LEN(TEXT)
|
||||
C = INDEX("abcdefghijklmnopqrstuvwxyz",TEXT(I:I))
|
||||
IF (C.GT.0) TEXT(I:I) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"(C:C)
|
||||
END DO
|
||||
END
|
||||
7
Task/String-case/K/string-case.k
Normal file
7
Task/String-case/K/string-case.k
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
s:"alphaBETA"
|
||||
upper:{i:_ic x; :[96<i; _ci i-32;_ci i]}'
|
||||
lower:{i:_ic x; :[91>i; _ci i+32;_ci i]}'
|
||||
upper s
|
||||
"ALPHABETA"
|
||||
lower s
|
||||
"alphabeta"
|
||||
|
|
@ -5,5 +5,4 @@ say $word.uc; # all uppercase (method call)
|
|||
say $word.lc; # all lowercase
|
||||
say $word.tc; # first letter titlecase
|
||||
say $word.tclc; # first letter titlecase, rest lowercase
|
||||
say $word.tcuc; # first letter titlecase, rest uppercase
|
||||
say $word.wordcase; # capitalize each word
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
$string = 'alphaBETA'
|
||||
$lower = $string.ToLower()
|
||||
$upper = $string.ToUpper()
|
||||
$title = (Get-Culture).TextInfo.ToTitleCase($string)
|
||||
|
||||
$lower, $upper, $title
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase letters*/
|
||||
abcU = translate(abc) /* " " " uppercase " */
|
||||
abc = "abcdefghijklmnopqrstuvwxyz" /*define all lowercase Latin letters.*/
|
||||
abcU = translate(abc) /* " " uppercase " " */
|
||||
|
||||
x = 'alphaBETA' /*define string to a REXX variable*/
|
||||
y = translate(x) /*uppercase X and store it───► Y*/
|
||||
z = translate(x, abc, abcU) /*tran uppercase──►lowercase chars*/
|
||||
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*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
x = "alphaBETA" /*define string to a REXX variable*/
|
||||
parse upper var x y /*uppercase X and store it───► Y*/
|
||||
parse lower var x z /*lowercase X " " " ───► Z*/
|
||||
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.*/
|
||||
/*Some REXXes don't support the LOWER option for the PARSE command.*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
x = 'alphaBETA' /*define string to a REXX variable*/
|
||||
y = upper(x) /*uppercase X and store it───► Y*/
|
||||
z = lower(x) /*lowercase X " " " ───► Z*/
|
||||
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). */
|
||||
/*Some REXXes don't support the UPPER and LOWER BIFs (built-in functions).*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
x = "alphaBETA" /*define string to a REXX variable*/
|
||||
y=x; upper y /*uppercase X and store it───► Y*/
|
||||
parse lower var x z /*lowercase Y " " " ───► Z*/
|
||||
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.*/
|
||||
/*Some REXXes don't support the LOWER option for the PARSE command.*/
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
/*REXX pgm capitalizes each word in string, maintains imbedded blanks.*/
|
||||
/*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." /*"old" spelling Hebrew letters. */
|
||||
y= capitalize(x) /*capitalize each word in string.*/
|
||||
say x /*show original string of words. */
|
||||
say y /*show the capitalized words. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*───────────────────────────────────CAPITALIZE subroutine──────────────*/
|
||||
capitalize: procedure; parse arg z; $=' 'z /*prefix with a blank.*/
|
||||
abc = "abcdefghijklmnopqrstuvwxyz" /*define all lowercase letters. */
|
||||
"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 alphabet*/
|
||||
_=' 'substr(abc,j,1); _U=_; upper _U /*get a lower and upper letter. */
|
||||
$ = changestr(_, $, _U) /*maybe capitalize some word(s). */
|
||||
end /*j*/
|
||||
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) /*capitalized words, -1st blank.*/
|
||||
return substr($, 2) /*return the capitalized words. */
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
/*REXX pgm swaps letter case of a string: lower──►upper & upper──►lower.*/
|
||||
abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase letters*/
|
||||
abcU = translate(abc) /* " " " uppercase " */
|
||||
/*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 string to a REXX variable*/
|
||||
y = translate(x,abc||abcU,abcU||abc) /*swap case of X store it ───► Y*/
|
||||
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 done.*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue