all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
1
Task/String-case/0DESCRIPTION
Normal file
1
Task/String-case/0DESCRIPTION
Normal file
|
|
@ -0,0 +1 @@
|
|||
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.
|
||||
2
Task/String-case/1META.yaml
Normal file
2
Task/String-case/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: String manipulation
|
||||
3
Task/String-case/4D/string-case.4d
Normal file
3
Task/String-case/4D/string-case.4d
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$string:="alphaBETA"
|
||||
$uppercase:=Uppercase($string)
|
||||
$lowercase:=Lowercase($string)
|
||||
101
Task/String-case/6502-Assembly/string-case.6502
Normal file
101
Task/String-case/6502-Assembly/string-case.6502
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
.lf case6502.lst
|
||||
.cr 6502
|
||||
.tf case6502.obj,ap1
|
||||
;------------------------------------------------------
|
||||
; String Case for the 6502 by barrym95838 2013.04.07
|
||||
; Thanks to sbprojects.com for a very nice assembler!
|
||||
; The target for this assembly is an Apple II with
|
||||
; mixed-case output capabilities. Apple IIs like to
|
||||
; work in '+128' ascii, so this version leaves bit 7
|
||||
; alone, and can be used with either flavor.
|
||||
; 6502s work best with data structures < 256 bytes;
|
||||
; several instructions would have to be added to
|
||||
; properly deal with longer strings.
|
||||
; Tested and verified on AppleWin 1.20.0.0
|
||||
;------------------------------------------------------
|
||||
; Constant Section
|
||||
;
|
||||
StrPtr = $6 0-page temp pointer (2 bytes)
|
||||
Low = $8 0-page temp low bound
|
||||
High = $9 0-page temp high bound
|
||||
CharOut = $fded Specific to the Apple II
|
||||
BigA = "A" 'A' for normal ascii
|
||||
BigZ = "Z" 'Z' " " "
|
||||
LittleA = "a" 'a' " " "
|
||||
LittleZ = "z" 'z' " " "
|
||||
;======================================================
|
||||
.or $0f00
|
||||
;------------------------------------------------------
|
||||
; The main program
|
||||
;
|
||||
main ldx #sTest Point to the test string
|
||||
lda /sTest
|
||||
jsr puts print it to stdout
|
||||
jsr toUpper convert to UPPER-case
|
||||
jsr puts print it
|
||||
jsr toLower convert to lower-case
|
||||
jmp puts print it and return to caller
|
||||
;------------------------------------------------------
|
||||
toUpper pha save A
|
||||
lda #LittleA
|
||||
sta Low set up the flip range
|
||||
lda #LittleZ
|
||||
bne toLow2 return via toLower's tail
|
||||
;------------------------------------------------------
|
||||
toLower pha save A
|
||||
lda #BigA
|
||||
sta Low set up the flip range
|
||||
lda #BigZ
|
||||
toLow2 sta High
|
||||
pla restore A
|
||||
; return via fall-thru to flip
|
||||
;------------------------------------------------------
|
||||
; Given a NUL-terminated string at A:X, flip the case
|
||||
; of any chars in the range [Low..High], inclusive;
|
||||
; only works on the first 256 bytes of a long string
|
||||
; Uses: StrPtr, Low, High
|
||||
; Preserves: A, X
|
||||
; Trashes: Y
|
||||
;
|
||||
flip stx StrPtr init string pointer
|
||||
sta StrPtr+1
|
||||
ldy #0
|
||||
pha save A
|
||||
flip2 lda (StrPtr),y get string char
|
||||
beq flip5 done if NUL
|
||||
cmp Low
|
||||
bcc flip4 if Low <= char <= High
|
||||
cmp High
|
||||
beq flip3
|
||||
bcs flip4
|
||||
flip3 eor #$20 then flip the case
|
||||
sta (StrPtr),y
|
||||
flip4 iny point to next char
|
||||
bne flip2 loop up to 255 times
|
||||
flip5 pla restore A
|
||||
rts return
|
||||
;------------------------------------------------------
|
||||
; Output NUL-terminated string @ A:X; strings longer
|
||||
; than 256 bytes are truncated there
|
||||
; Uses: StrPtr
|
||||
; Preserves: A, X
|
||||
; Trashes: Y
|
||||
;
|
||||
puts stx StrPtr init string pointer
|
||||
sta StrPtr+1
|
||||
ldy #0
|
||||
pha save A
|
||||
puts2 lda (StrPtr),y get string char
|
||||
beq puts3 done if NUL
|
||||
jsr CharOut output the char
|
||||
iny point to next char
|
||||
bne puts2 loop up to 255 times
|
||||
puts3 pla restore A
|
||||
rts return
|
||||
;------------------------------------------------------
|
||||
; Test String (in '+128' ascii, Apple II style)
|
||||
;
|
||||
sTest .as -"Alpha, BETA, gamma, {[(<123@_>)]}."
|
||||
.az -#13
|
||||
;------------------------------------------------------
|
||||
.en
|
||||
31
Task/String-case/ALGOL-68/string-case.alg
Normal file
31
Task/String-case/ALGOL-68/string-case.alg
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/local/bin/a68g --script #
|
||||
|
||||
# Demonstrate toupper and tolower for standard ALGOL 68
|
||||
strings. This does not work for multibyte character sets. #
|
||||
|
||||
INT l2u = ABS "A" - ABS "a";
|
||||
|
||||
PROC to upper = (CHAR c)CHAR:
|
||||
(ABS "a" > ABS c | c |: ABS c > ABS "z" | c | REPR ( ABS c + l2u ));
|
||||
|
||||
PROC to lower = (CHAR c)CHAR:
|
||||
(ABS "A" > ABS c | c |: ABS c > ABS "Z" | c | REPR ( ABS c - l2u ));
|
||||
|
||||
# Operators can be defined in ALGOL 68 #
|
||||
OP (CHAR)CHAR TOLOWER = to lower, TOUPPER = to upper;
|
||||
|
||||
# upper-cases s in place #
|
||||
PROC string to upper = (REF STRING s)VOID:
|
||||
FOR i FROM LWB s TO UPB s DO s[i] := to upper(s[i]) OD;
|
||||
|
||||
# lower-cases s in place #
|
||||
PROC string to lower = (REF STRING s)VOID:
|
||||
FOR i FROM LWB s TO UPB s DO s[i] := to lower(s[i]) OD;
|
||||
|
||||
main: (
|
||||
STRING t := "alphaBETA";
|
||||
string to upper(t);
|
||||
printf(($"uppercase: "gl$, t));
|
||||
string to lower(t);
|
||||
printf(($"lowercase: "gl$, t))
|
||||
)
|
||||
9
Task/String-case/APL/string-case.apl
Normal file
9
Task/String-case/APL/string-case.apl
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
AlphLower←'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
AlphUpper←'ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ*'
|
||||
AlphUpper[AlphLower⍳'I'm using APL!']
|
||||
I*M USING APL*
|
||||
|
||||
AlphLower←'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ*'
|
||||
AlphUpper←'ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
AlphLower[AlphUpper⍳'I'm using APL!']
|
||||
i*m using apl*
|
||||
4
Task/String-case/AWK/string-case-1.awk
Normal file
4
Task/String-case/AWK/string-case-1.awk
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BEGIN {
|
||||
a = "alphaBETA";
|
||||
print toupper(a), tolower(a)
|
||||
}
|
||||
4
Task/String-case/AWK/string-case-2.awk
Normal file
4
Task/String-case/AWK/string-case-2.awk
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
BEGIN {
|
||||
a = "alphaBETA";
|
||||
print toupper(substr(a, 1, 1)) tolower(substr(a, 2))
|
||||
}
|
||||
3
Task/String-case/ActionScript/string-case.as
Normal file
3
Task/String-case/ActionScript/string-case.as
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var string:String = 'alphaBETA';
|
||||
var upper:String = string.toUpperCase();
|
||||
var lower:String = string.toLowerCase();
|
||||
9
Task/String-case/Ada/string-case.ada
Normal file
9
Task/String-case/Ada/string-case.ada
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
with Ada.Characters.Handling; use Ada.Characters.Handling;
|
||||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
|
||||
procedure Upper_Case_String is
|
||||
S : String := "alphaBETA";
|
||||
begin
|
||||
Put_Line(To_Upper(S));
|
||||
Put_Line(To_Lower(S));
|
||||
end Upper_Case_String;
|
||||
2
Task/String-case/Arbre/string-case.arbre
Normal file
2
Task/String-case/Arbre/string-case.arbre
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
main():
|
||||
uppercase('alphaBETA') + '\n' + lowercase('alphaBETA') + '\n' -> io
|
||||
5
Task/String-case/AutoHotkey/string-case.ahk
Normal file
5
Task/String-case/AutoHotkey/string-case.ahk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a := "alphaBETA"
|
||||
StringLower, b, a ; alphabeta
|
||||
StringUpper, c, a ; ALPHABETA
|
||||
|
||||
StringUpper, d, a, T ; Alphabeta (T = title case) eg "alpha beta gamma" would become "Alpha Beta Gamma"
|
||||
3
Task/String-case/AutoIt/string-case.autoit
Normal file
3
Task/String-case/AutoIt/string-case.autoit
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$sString = "alphaBETA"
|
||||
$sUppercase = StringUpper($sString) ;"ALPHABETA"
|
||||
$sLowercase = StringLower($sString) ;"alphabeta"
|
||||
3
Task/String-case/BASIC/string-case.basic
Normal file
3
Task/String-case/BASIC/string-case.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s$ = "alphaBETA"
|
||||
PRINT UCASE$(s$)
|
||||
PRINT LCASE$(s$)
|
||||
7
Task/String-case/BBC-BASIC/string-case.bbc
Normal file
7
Task/String-case/BBC-BASIC/string-case.bbc
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
INSTALL @lib$+"STRINGLIB"
|
||||
|
||||
original$ = "alphaBETA"
|
||||
PRINT "Original: " original$
|
||||
PRINT "Lower case: " FN_lower(original$)
|
||||
PRINT "Upper case: " FN_upper(original$)
|
||||
PRINT "Title case: " FN_title(original$)
|
||||
4
Task/String-case/Befunge/string-case.bf
Normal file
4
Task/String-case/Befunge/string-case.bf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"ATEBahpla" > : #v_ 25* , @ >48*-v
|
||||
> :: "`"` \"{"\` * | > , v
|
||||
> ^
|
||||
^ <
|
||||
2
Task/String-case/Bracmat/string-case.bracmat
Normal file
2
Task/String-case/Bracmat/string-case.bracmat
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"alphaBETA":?s
|
||||
& out$str$(upp$!s \n low$!s)
|
||||
3
Task/String-case/Burlesque/string-case.blq
Normal file
3
Task/String-case/Burlesque/string-case.blq
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
blsq ) "alphaBETA"^^zz\/ZZ
|
||||
"ALPHABETA"
|
||||
"alphabeta"
|
||||
21
Task/String-case/C++/string-case-1.cpp
Normal file
21
Task/String-case/C++/string-case-1.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
|
||||
/// \brief in-place convert string to upper case
|
||||
/// \return ref to transformed string
|
||||
void str_toupper(std::string &str) {
|
||||
std::transform(str.begin(),
|
||||
str.end(),
|
||||
str.begin(),
|
||||
(int(*)(int)) std::toupper);
|
||||
}
|
||||
|
||||
/// \brief in-place convert string to lower case
|
||||
/// \return ref to transformed string
|
||||
void str_tolower(std::string &str) {
|
||||
std::transform(str.begin(),
|
||||
str.end(),
|
||||
str.begin(),
|
||||
(int(*)(int)) std::tolower);
|
||||
}
|
||||
12
Task/String-case/C++/string-case-2.cpp
Normal file
12
Task/String-case/C++/string-case-2.cpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
int main() {
|
||||
string foo("_upperCas3Me!!");
|
||||
str_toupper(foo);
|
||||
cout << foo << endl;
|
||||
str_tolower(foo);
|
||||
cout << foo << endl;
|
||||
return 0;
|
||||
}
|
||||
36
Task/String-case/C/string-case.c
Normal file
36
Task/String-case/C/string-case.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* Demonstrate toupper and tolower for
|
||||
standard C strings.
|
||||
This does not work for multibyte character sets. */
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* upper-cases s in place */
|
||||
void str_toupper(char *s)
|
||||
{
|
||||
while(*s)
|
||||
{
|
||||
*s=toupper(*s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* lower-cases s in place */
|
||||
void str_tolower(char *s)
|
||||
{
|
||||
while(*s)
|
||||
{
|
||||
*s=tolower(*s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char t[255]="alphaBETA";
|
||||
str_toupper(t);
|
||||
printf("uppercase: %s\n", t);
|
||||
str_tolower(t);
|
||||
printf("lowercase: %s\n", t);
|
||||
return 0;
|
||||
}
|
||||
4
Task/String-case/CMake/string-case.cmake
Normal file
4
Task/String-case/CMake/string-case.cmake
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
string(TOUPPER alphaBETA s)
|
||||
message(STATUS "Uppercase: ${s}")
|
||||
string(TOLOWER alphaBETA s)
|
||||
message(STATUS "Lowercase: ${s}")
|
||||
3
Task/String-case/Clojure/string-case.clj
Normal file
3
Task/String-case/Clojure/string-case.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(def string "alphaBETA")
|
||||
(println (.toUpperCase string))
|
||||
(println (.toLowerCase string))
|
||||
2
Task/String-case/ColdFusion/string-case-1.cfm
Normal file
2
Task/String-case/ColdFusion/string-case-1.cfm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
<cfset upper = UCase("alphaBETA")>
|
||||
<cfset lower = LCase("alphaBETA")>
|
||||
3
Task/String-case/ColdFusion/string-case-2.cfm
Normal file
3
Task/String-case/ColdFusion/string-case-2.cfm
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<cfset string = "alphaBETA">
|
||||
<cfset upper = UCase(string)>
|
||||
<cfset lower = LCase(string)>
|
||||
2
Task/String-case/Common-Lisp/string-case-1.lisp
Normal file
2
Task/String-case/Common-Lisp/string-case-1.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
CL-USER> (string-upcase "alphaBETA")
|
||||
"ALPHABETA"
|
||||
2
Task/String-case/Common-Lisp/string-case-2.lisp
Normal file
2
Task/String-case/Common-Lisp/string-case-2.lisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
CL-USER> (string-downcase "alphaBETA")
|
||||
"alphabeta"
|
||||
7
Task/String-case/D/string-case.d
Normal file
7
Task/String-case/D/string-case.d
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import std.stdio, std.string;
|
||||
|
||||
void main() {
|
||||
auto s = "alphaBETA";
|
||||
writeln(s.toUpper());
|
||||
writeln(s.toLower());
|
||||
}
|
||||
2
Task/String-case/DWScript/string-case.dwscript
Normal file
2
Task/String-case/DWScript/string-case.dwscript
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
PrintLn(UpperCase('alphaBETA'));
|
||||
PrintLn(LowerCase('alphaBETA'));
|
||||
2
Task/String-case/Delphi/string-case.delphi
Normal file
2
Task/String-case/Delphi/string-case.delphi
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
writeln(uppercase('alphaBETA'));
|
||||
writeln(lowercase('alphaBETA'));
|
||||
2
Task/String-case/E/string-case.e
Normal file
2
Task/String-case/E/string-case.e
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
["alphaBETA".toUpperCase(),
|
||||
"alphaBETA".toLowerCase()]
|
||||
2
Task/String-case/Erlang/string-case.erl
Normal file
2
Task/String-case/Erlang/string-case.erl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
string:to_upper("alphaBETA").
|
||||
string:to_lower("alphaBETA").
|
||||
4
Task/String-case/Factor/string-case.factor
Normal file
4
Task/String-case/Factor/string-case.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"alphaBETA" >lower ! "alphabeta"
|
||||
"alphaBETA" >upper ! "ALPHABETA"
|
||||
"alphaBETA" >title ! "Alphabeta"
|
||||
"ß" >case-fold ! "ss"
|
||||
2
Task/String-case/Falcon/string-case.falcon
Normal file
2
Task/String-case/Falcon/string-case.falcon
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
printl("alphaBETA".lower())
|
||||
printl("alphaBETA".upper())
|
||||
10
Task/String-case/Fantom/string-case.fantom
Normal file
10
Task/String-case/Fantom/string-case.fantom
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fansh> a := "alphaBETA"
|
||||
alphaBETA
|
||||
fansh> a.upper // convert whole string to upper case
|
||||
ALPHABETA
|
||||
fansh> a.lower // convert whole string to lower case
|
||||
alphabeta
|
||||
fansh> a.capitalize // make sure first letter is capital
|
||||
AlphaBETA
|
||||
fansh> "BETAalpha".decapitalize // make sure first letter is not capital
|
||||
bETAalpha
|
||||
38
Task/String-case/Fortran/string-case.f
Normal file
38
Task/String-case/Fortran/string-case.f
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
program example
|
||||
|
||||
implicit none
|
||||
|
||||
character(9) :: teststring = "alphaBETA"
|
||||
|
||||
call To_upper(teststring)
|
||||
write(*,*) teststring
|
||||
call To_lower(teststring)
|
||||
write(*,*) teststring
|
||||
|
||||
contains
|
||||
|
||||
subroutine To_upper(str)
|
||||
character(*), intent(in out) :: str
|
||||
integer :: i
|
||||
|
||||
do i = 1, len(str)
|
||||
select case(str(i:i))
|
||||
case("a":"z")
|
||||
str(i:i) = achar(iachar(str(i:i))-32)
|
||||
end select
|
||||
end do
|
||||
end subroutine To_upper
|
||||
|
||||
subroutine To_lower(str)
|
||||
character(*), intent(in out) :: str
|
||||
integer :: i
|
||||
|
||||
do i = 1, len(str)
|
||||
select case(str(i:i))
|
||||
case("A":"Z")
|
||||
str(i:i) = achar(iachar(str(i:i))+32)
|
||||
end select
|
||||
end do
|
||||
end subroutine To_Lower
|
||||
|
||||
end program example
|
||||
8
Task/String-case/GML/string-case.gml
Normal file
8
Task/String-case/GML/string-case.gml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#define cases
|
||||
{
|
||||
x = 'alphaBETA';
|
||||
y = string_upper(x); // returns ALPHABETA
|
||||
z = string_lower(x); // returns alphabeta
|
||||
show_message(y);
|
||||
show_message(z);
|
||||
}
|
||||
25
Task/String-case/Go/string-case.go
Normal file
25
Task/String-case/Go/string-case.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
show("alphaBETA")
|
||||
show("alpha BETA")
|
||||
show("DŽLjnj") // should render similar to DZLjnj
|
||||
}
|
||||
|
||||
func show(s string) {
|
||||
fmt.Println("\nstring: ", s, "len:", utf8.RuneCountInString(s))
|
||||
fmt.Println("All upper case: ", strings.ToUpper(s)) // DZLJNJ
|
||||
fmt.Println("All lower case: ", strings.ToLower(s)) // dzljnj
|
||||
fmt.Println("All title case: ", strings.ToTitle(s)) // DzLjNj
|
||||
// notice Title() only modifies first letters of words
|
||||
// non-first letters keep their case.
|
||||
fmt.Println("Title words: ", strings.Title(s)) // Dzljnj
|
||||
fmt.Println("Swapping case: ", strings.Map(unicode.SimpleFold, s))
|
||||
}
|
||||
4
Task/String-case/Groovy/string-case.groovy
Normal file
4
Task/String-case/Groovy/string-case.groovy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def str = 'alphaBETA'
|
||||
|
||||
println str.toUpperCase()
|
||||
println str.toLowerCase()
|
||||
6
Task/String-case/Haskell/string-case.hs
Normal file
6
Task/String-case/Haskell/string-case.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import Data.Char
|
||||
|
||||
s = "alphaBETA"
|
||||
|
||||
lower = map toLower s
|
||||
upper = map toUpper s
|
||||
4
Task/String-case/HicEst/string-case.hicest
Normal file
4
Task/String-case/HicEst/string-case.hicest
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
CHARACTER str = "alphaBETA"
|
||||
EDIT(Text=str, UpperCase=LEN(str))
|
||||
EDIT(Text=str, LowerCase=LEN(str))
|
||||
EDIT(Text=str, UpperCase=1)
|
||||
4
Task/String-case/Icon/string-case.icon
Normal file
4
Task/String-case/Icon/string-case.icon
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
procedure main()
|
||||
write(map("alphaBETA"))
|
||||
write(map("alphaBETA",&lcase,&ucase))
|
||||
end
|
||||
4
Task/String-case/J/string-case-1.j
Normal file
4
Task/String-case/J/string-case-1.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
toupper 'alphaBETA'
|
||||
ALPHABETA
|
||||
tolower 'alphaBETA'
|
||||
alphabeta
|
||||
2
Task/String-case/J/string-case-2.j
Normal file
2
Task/String-case/J/string-case-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
upper=: {&((65+i.26) +&32@[} i.256)&.(a.&i.)
|
||||
lower=: {&((97+i.26) -&32@[} i.256)&.(a.&i.)
|
||||
4
Task/String-case/J/string-case-3.j
Normal file
4
Task/String-case/J/string-case-3.j
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
upper 'alphaBETA'
|
||||
ALPHABETA
|
||||
lower 'alphaBETA'
|
||||
alphabeta
|
||||
6
Task/String-case/Java/string-case.java
Normal file
6
Task/String-case/Java/string-case.java
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
String str = "alphaBETA";
|
||||
System.out.println(str.toUpperCase());
|
||||
System.out.println(str.toLowerCase());
|
||||
//Also works with non-English characters with no modification
|
||||
System.out.println("äàâáçñßæεбế".toUpperCase());
|
||||
System.out.println("ÄÀÂÁÇÑSSÆΕБẾ".toLowerCase()); //does not transalate "SS" to "ß"
|
||||
2
Task/String-case/JavaScript/string-case-1.js
Normal file
2
Task/String-case/JavaScript/string-case-1.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
alert( "alphaBETA".toUpperCase() );
|
||||
alert( "alphaBETA".toLowerCase() );
|
||||
3
Task/String-case/JavaScript/string-case-2.js
Normal file
3
Task/String-case/JavaScript/string-case-2.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var string = "alphaBETA";
|
||||
var uppercase = string.toUpperCase();
|
||||
var lowercase = string.toLowerCase();
|
||||
7
Task/String-case/Liberty-BASIC/string-case.liberty
Normal file
7
Task/String-case/Liberty-BASIC/string-case.liberty
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
input$ ="alphaBETA"
|
||||
|
||||
print input$
|
||||
print upper$( input$)
|
||||
print lower$( input$)
|
||||
|
||||
end
|
||||
3
Task/String-case/Lua/string-case.lua
Normal file
3
Task/String-case/Lua/string-case.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
str = "alphaBETA"
|
||||
print( string.upper(str) )
|
||||
print( string.lower(str) )
|
||||
6
Task/String-case/M4/string-case.m4
Normal file
6
Task/String-case/M4/string-case.m4
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
define(`upcase', `translit(`$*', `a-z', `A-Z')')
|
||||
define(`downcase', `translit(`$*', `A-Z', `a-z')')
|
||||
|
||||
define(`x',`alphaBETA')
|
||||
upcase(x)
|
||||
downcase(x)
|
||||
11
Task/String-case/MATLAB/string-case.m
Normal file
11
Task/String-case/MATLAB/string-case.m
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
>> upper('alphaBETA')
|
||||
|
||||
ans =
|
||||
|
||||
ALPHABETA
|
||||
|
||||
>> lower('alphaBETA')
|
||||
|
||||
ans =
|
||||
|
||||
alphabeta
|
||||
3
Task/String-case/MAXScript/string-case.maxscript
Normal file
3
Task/String-case/MAXScript/string-case.maxscript
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
str = "alphaBETA"
|
||||
print (toUpper str)
|
||||
print (toLower str)
|
||||
7
Task/String-case/MUMPS/string-case.mumps
Normal file
7
Task/String-case/MUMPS/string-case.mumps
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
STRCASE(S)
|
||||
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
SET LO="abcdefghijklmnopqrstuvwxyz"
|
||||
WRITE !,"Given: "_S
|
||||
WRITE !,"Upper: "_$TRANSLATE(S,LO,UP)
|
||||
WRITE !,"Lower: "_$TRANSLATE(S,UP,LO)
|
||||
QUIT
|
||||
3
Task/String-case/Mathematica/string-case.math
Normal file
3
Task/String-case/Mathematica/string-case.math
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
str="alphaBETA";
|
||||
ToUpperCase[str]
|
||||
ToLowerCase[str]
|
||||
16
Task/String-case/Mercury/string-case.mercury
Normal file
16
Task/String-case/Mercury/string-case.mercury
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
:- module string_case.
|
||||
:- interface.
|
||||
|
||||
:- import_module io.
|
||||
:- pred main(io::di, io::uo) is det.
|
||||
|
||||
:- implementation.
|
||||
:- import_module list, string.
|
||||
|
||||
main(!IO) :-
|
||||
S = "alphaBETA",
|
||||
io.format("uppercase : %s\n", [s(to_upper(S))], !IO),
|
||||
io.format("lowercase : %s\n", [s(to_lower(S))], !IO),
|
||||
io.format("capitalize first: %s\n", [s(capitalize_first(S))], !IO).
|
||||
% We can use uncaptitalize_first/1 to ensure the first character in a
|
||||
% string is lower-case.
|
||||
34
Task/String-case/Metafont/string-case-1.metafont
Normal file
34
Task/String-case/Metafont/string-case-1.metafont
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
vardef isbetween(expr a, i, f) =
|
||||
if string a:
|
||||
if (ASCII(a) >= ASCII(i)) and (ASCII(a) <= ASCII(f)):
|
||||
true
|
||||
else:
|
||||
false
|
||||
fi
|
||||
else:
|
||||
false
|
||||
fi enddef;
|
||||
|
||||
vardef toupper(expr s) =
|
||||
save ?; string ?; ? := ""; d := ASCII"A" - ASCII"a";
|
||||
for i = 0 upto length(s)-1:
|
||||
if isbetween(substring(i, i+1) of s, "a", "z"):
|
||||
? := ? & char(ASCII(substring(i,i+1) of s) + d)
|
||||
else:
|
||||
? := ? & substring(i, i+1) of s
|
||||
fi;
|
||||
endfor
|
||||
?
|
||||
enddef;
|
||||
|
||||
vardef tolower(expr s) =
|
||||
save ?; string ?; ? := ""; d := ASCII"a" - ASCII"A";
|
||||
for i = 0 upto length(s)-1:
|
||||
if isbetween(substring(i, i+1) of s, "A", "Z"):
|
||||
? := ? & char(ASCII(substring(i,i+1) of s) + d)
|
||||
else:
|
||||
? := ? & substring(i, i+1) of s
|
||||
fi;
|
||||
endfor
|
||||
?
|
||||
enddef;
|
||||
4
Task/String-case/Metafont/string-case-2.metafont
Normal file
4
Task/String-case/Metafont/string-case-2.metafont
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
message toupper("alphaBETA");
|
||||
message tolower("alphaBETA");
|
||||
|
||||
end
|
||||
30
Task/String-case/Modula-3/string-case.mod3
Normal file
30
Task/String-case/Modula-3/string-case.mod3
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
MODULE TextCase EXPORTS Main;
|
||||
|
||||
IMPORT IO, Text, ASCII;
|
||||
|
||||
PROCEDURE Upper(txt: TEXT): TEXT =
|
||||
VAR
|
||||
len := Text.Length(txt);
|
||||
res := "";
|
||||
BEGIN
|
||||
FOR i := 0 TO len - 1 DO
|
||||
res := Text.Cat(res, Text.FromChar(ASCII.Upper[Text.GetChar(txt, i)]));
|
||||
END;
|
||||
RETURN res;
|
||||
END Upper;
|
||||
|
||||
PROCEDURE Lower(txt: TEXT): TEXT =
|
||||
VAR
|
||||
len := Text.Length(txt);
|
||||
res := "";
|
||||
BEGIN
|
||||
FOR i := 0 TO len - 1 DO
|
||||
res := Text.Cat(res, Text.FromChar(ASCII.Lower[Text.GetChar(txt, i)]));
|
||||
END;
|
||||
RETURN res;
|
||||
END Lower;
|
||||
|
||||
BEGIN
|
||||
IO.Put(Upper("alphaBETA\n"));
|
||||
IO.Put(Lower("alphaBETA\n"));
|
||||
END TextCase.
|
||||
15
Task/String-case/Nemerle/string-case.nemerle
Normal file
15
Task/String-case/Nemerle/string-case.nemerle
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System.Console;
|
||||
using System.Globalization;
|
||||
|
||||
module StringCase
|
||||
{
|
||||
Main() : void
|
||||
{
|
||||
def alpha = "alphaBETA";
|
||||
WriteLine(alpha.ToUpper());
|
||||
WriteLine(alpha.ToLower());
|
||||
|
||||
WriteLine(CultureInfo.CurrentCulture.TextInfo.ToTitleCase("exAmpLe sTrinG"));
|
||||
|
||||
}
|
||||
}
|
||||
9
Task/String-case/NetRexx/string-case.netrexx
Normal file
9
Task/String-case/NetRexx/string-case.netrexx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/* NetRexx */
|
||||
|
||||
options replace format comments java crossref savelog symbols
|
||||
|
||||
abc = 'alphaBETA'
|
||||
|
||||
say abc.upper
|
||||
say abc.lower
|
||||
say abc.upper(1, 1) -- capitalize 1st character
|
||||
2
Task/String-case/NewLISP/string-case.newlisp
Normal file
2
Task/String-case/NewLISP/string-case.newlisp
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(upper-case "alphaBETA")
|
||||
(lower-case "alphaBETA")
|
||||
4
Task/String-case/Nial/string-case.nial
Normal file
4
Task/String-case/Nial/string-case.nial
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
toupper 'alphaBETA'
|
||||
=ALPHABETA
|
||||
tolower 'alphaBETA'
|
||||
=alphabeta
|
||||
7
Task/String-case/OCaml/string-case.ocaml
Normal file
7
Task/String-case/OCaml/string-case.ocaml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
let () =
|
||||
let str = "alphaBETA" in
|
||||
print_endline (String.uppercase str); (* ALPHABETA *)
|
||||
print_endline (String.lowercase str); (* alphabeta *)
|
||||
|
||||
print_endline (String.capitalize str); (* AlphaBETA *)
|
||||
;;
|
||||
3
Task/String-case/Objeck/string-case.objeck
Normal file
3
Task/String-case/Objeck/string-case.objeck
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
string := "alphaBETA";
|
||||
string->ToUpper()->PrintLine();
|
||||
string->ToLower()->PrintLine();
|
||||
4
Task/String-case/Objective-C/string-case.m
Normal file
4
Task/String-case/Objective-C/string-case.m
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
NSLog(@"%@", [@"alphaBETA" uppercaseString]);
|
||||
NSLog(@"%@", [@"alphaBETA" lowercaseString]);
|
||||
|
||||
NSLog(@"%@", [@"foO BAr" capitalizedString]); // "Foo Bar"
|
||||
5
Task/String-case/Octave/string-case.octave
Normal file
5
Task/String-case/Octave/string-case.octave
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
s = "alphaBETA";
|
||||
slc = tolower(s);
|
||||
suc = toupper(s);
|
||||
disp(slc);
|
||||
disp(suc);
|
||||
2
Task/String-case/OpenEdge-Progress/string-case.openedge
Normal file
2
Task/String-case/OpenEdge-Progress/string-case.openedge
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
caps("alphaBETA")
|
||||
lc("alphaBETA")
|
||||
5
Task/String-case/OxygenBasic/string-case.oxy
Normal file
5
Task/String-case/OxygenBasic/string-case.oxy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
string s="alphaBETA"
|
||||
|
||||
print lcase(s) " "+
|
||||
ucase(s) " "+
|
||||
ucase(left(s,1))+mid(s,2) 'capitalised
|
||||
5
Task/String-case/Oz/string-case-1.oz
Normal file
5
Task/String-case/Oz/string-case-1.oz
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
declare
|
||||
Str = "alphaBETA"
|
||||
in
|
||||
{System.showInfo {Map Str Char.toUpper}}
|
||||
{System.showInfo {Map Str Char.toLower}}
|
||||
4
Task/String-case/Oz/string-case-2.oz
Normal file
4
Task/String-case/Oz/string-case-2.oz
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
declare
|
||||
[StringX] = {Link ['x-oz://system/String.ozf']}
|
||||
in
|
||||
{System.showInfo {StringX.capitalize "alphaBETA"}} %% prints "AlphaBETA"
|
||||
8
Task/String-case/PHP/string-case.php
Normal file
8
Task/String-case/PHP/string-case.php
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
$str = "alphaBETA";
|
||||
echo strtoupper($str), "\n"; // ALPHABETA
|
||||
echo strtolower($str), "\n"; // alphabeta
|
||||
|
||||
echo ucfirst($str), "\n"; // AlphaBETA
|
||||
echo lcfirst("FOObar"), "\n"; // fOObar
|
||||
echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ
|
||||
echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz
|
||||
4
Task/String-case/PL-I/string-case-1.pli
Normal file
4
Task/String-case/PL-I/string-case-1.pli
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
declare s character (20) varying initial ('alphaBETA');
|
||||
|
||||
put skip list (uppercase(s));
|
||||
put skip list (lowercase(s));
|
||||
5
Task/String-case/PL-I/string-case-2.pli
Normal file
5
Task/String-case/PL-I/string-case-2.pli
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* An alternative to the above, which might be used if some */
|
||||
/* non-standard conversion is required, is shown for */
|
||||
/* converting to upper case: */
|
||||
put skip list ( translate(s, 'abcdefghijklmnopqrstuvwxyz',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ') );
|
||||
10
Task/String-case/PL-SQL/string-case.sql
Normal file
10
Task/String-case/PL-SQL/string-case.sql
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
declare
|
||||
vc VARCHAR2(40) := 'alphaBETA';
|
||||
ivc VARCHAR2(40);
|
||||
lvc VARCHAR2(40);
|
||||
uvc VARCHAR2(40);
|
||||
begin
|
||||
ivc := INITCAP(vc); -- 'Alphabeta'
|
||||
lvc := LOWER(vc); -- 'alphabeta'
|
||||
uvc := UPPER(vc); -- 'ALPHABETA'
|
||||
end;
|
||||
9
Task/String-case/Perl-6/string-case.pl6
Normal file
9
Task/String-case/Perl-6/string-case.pl6
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
my $word = "alpha BETA" ;
|
||||
say uc $word; # all uppercase (subroutine call)
|
||||
say $word.uc; # all uppercase (method call)
|
||||
# from now on we use only method calls as examples
|
||||
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
|
||||
7
Task/String-case/Perl/string-case.pl
Normal file
7
Task/String-case/Perl/string-case.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
my $string = "alphaBETA";
|
||||
print uc($string), "\n"; # => "ALPHABETA"
|
||||
print lc($string), "\n"; # => "alphabeta"
|
||||
$string =~ tr/[a-z][A-Z]/[A-Z][a-z]/; print "$string\n"; # => ALPHAbeta
|
||||
|
||||
print ucfirst($string), "\n"; # => "AlphaBETA"
|
||||
print lcfirst("FOObar"), "\n"; # => "fOObar"
|
||||
3
Task/String-case/PicoLisp/string-case.l
Normal file
3
Task/String-case/PicoLisp/string-case.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(let Str "alphaBETA"
|
||||
(prinl (uppc Str))
|
||||
(prinl (lowc Str)) )
|
||||
3
Task/String-case/Pop11/string-case.pop11
Normal file
3
Task/String-case/Pop11/string-case.pop11
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
lvars str = 'alphaBETA';
|
||||
lowertoupper(str) =>
|
||||
uppertolower(str) =>
|
||||
3
Task/String-case/PowerShell/string-case.psh
Normal file
3
Task/String-case/PowerShell/string-case.psh
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$string = 'alphaBETA'
|
||||
$lower = $string.ToLower()
|
||||
$upper = $string.ToUpper()
|
||||
5
Task/String-case/Protium/string-case-1.protium
Normal file
5
Task/String-case/Protium/string-case-1.protium
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<@ ENU$$$LSTPSTLITLIT>UPP|
|
||||
[<@ SAYELTLST>...</@>] <@ SAYHLPELTLST>...</@><@ DEFKEYELTLST>__SuperMacro|...</@>
|
||||
<@ SAY&&&LIT>alphaBETA</@>
|
||||
|
||||
</@>
|
||||
5
Task/String-case/Protium/string-case-2.protium
Normal file
5
Task/String-case/Protium/string-case-2.protium
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<# ENUMERATION LAMBDA LIST PEERSET LITERAL LITERAL>UPP|
|
||||
[<# SAY ELEMENT LIST>...</#>] <# SAY HELP ELEMENT LIST>...</#><# DEFINE KEYWORD ELEMENT LIST>__SuperMacro|...</#>
|
||||
<# SAY SUPERMACRO LITERAL>alphaBETA</#>
|
||||
|
||||
</#>
|
||||
3
Task/String-case/PureBasic/string-case.purebasic
Normal file
3
Task/String-case/PureBasic/string-case.purebasic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
s$ = "alphaBETA"
|
||||
upper$ = UCase(s$) ;uppercase
|
||||
lower$ = LCase(s$) ;lowercase
|
||||
11
Task/String-case/Python/string-case-1.py
Normal file
11
Task/String-case/Python/string-case-1.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
s = "alphaBETA"
|
||||
print s.upper() # => "ALPHABETA"
|
||||
print s.lower() # => "alphabeta"
|
||||
|
||||
print s.swapcase() # => "ALPHAbeta"
|
||||
|
||||
print "fOo bAR".capitalize() # => "Foo bar"
|
||||
print "fOo bAR".title() # => "Foo Bar"
|
||||
|
||||
import string
|
||||
print string.capwords("fOo bAR") # => "Foo Bar"
|
||||
2
Task/String-case/Python/string-case-2.py
Normal file
2
Task/String-case/Python/string-case-2.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
print "foo's bar".title() # => "Foo'S Bar"
|
||||
print string.capwords("foo's bar") # => "Foo's Bar"
|
||||
3
Task/String-case/R/string-case.r
Normal file
3
Task/String-case/R/string-case.r
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
str <- "alphaBETA"
|
||||
toupper(str)
|
||||
tolower(str)
|
||||
3
Task/String-case/REBOL/string-case.rebol
Normal file
3
Task/String-case/REBOL/string-case.rebol
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
print ["Original: " original: "alphaBETA"]
|
||||
print ["Uppercase:" uppercase original]
|
||||
print ["Lowercase:" lowercase original]
|
||||
6
Task/String-case/REXX/string-case-1.rexx
Normal file
6
Task/String-case/REXX/string-case-1.rexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase 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*/
|
||||
5
Task/String-case/REXX/string-case-2.rexx
Normal file
5
Task/String-case/REXX/string-case-2.rexx
Normal file
|
|
@ -0,0 +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*/
|
||||
|
||||
/*Some REXXes don't support the LOWER option for the PARSE command.*/
|
||||
6
Task/String-case/REXX/string-case-3.rexx
Normal file
6
Task/String-case/REXX/string-case-3.rexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
x = 'alphaBETA' /*define 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). */
|
||||
5
Task/String-case/REXX/string-case-4.rexx
Normal file
5
Task/String-case/REXX/string-case-4.rexx
Normal file
|
|
@ -0,0 +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*/
|
||||
|
||||
/*Some REXXes don't support the LOWER option for the PARSE command.*/
|
||||
17
Task/String-case/REXX/string-case-5.rexx
Normal file
17
Task/String-case/REXX/string-case-5.rexx
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/*REXX pgm capitalizes each word in string, 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. */
|
||||
|
||||
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*/
|
||||
|
||||
return substr($,2) /*capitalized words, -1st blank.*/
|
||||
9
Task/String-case/REXX/string-case-6.rexx
Normal file
9
Task/String-case/REXX/string-case-6.rexx
Normal file
|
|
@ -0,0 +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 " */
|
||||
|
||||
x = 'alphaBETA' /*define string to a REXX variable*/
|
||||
y = translate(x,abc||abcU,abcU||abc) /*swap case of X store it ───► Y*/
|
||||
say x
|
||||
say y
|
||||
/*stick a fork in it, we're done.*/
|
||||
11
Task/String-case/REXX/string-case-7.rexx
Normal file
11
Task/String-case/REXX/string-case-7.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
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
|
||||
8
Task/String-case/REXX/string-case-8.rexx
Normal file
8
Task/String-case/REXX/string-case-8.rexx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
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 */
|
||||
2
Task/String-case/Raven/string-case.raven
Normal file
2
Task/String-case/Raven/string-case.raven
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
'alphaBETA' upper
|
||||
'alhpaBETA' lower
|
||||
3
Task/String-case/Retro/string-case.retro
Normal file
3
Task/String-case/Retro/string-case.retro
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
with strings'
|
||||
"alphaBETA" toUpper puts
|
||||
"alphaBETA" toLower puts
|
||||
5
Task/String-case/Ruby/string-case.rb
Normal file
5
Task/String-case/Ruby/string-case.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"alphaBETA".downcase # => "alphabeta"
|
||||
"alphaBETA".upcase # => "ALPHABETA"
|
||||
|
||||
"alphaBETA".swapcase # => "ALPHAbeta"
|
||||
"alphaBETA".capitalize # => "Alphabeta"
|
||||
5
Task/String-case/Run-BASIC/string-case.run
Normal file
5
Task/String-case/Run-BASIC/string-case.run
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a$ ="alphaBETA"
|
||||
|
||||
print a$ '=> alphaBETA
|
||||
print upper$(a$) '=> ALPHABETA
|
||||
print lower$(a$) '=> alphabeta
|
||||
26
Task/String-case/SNOBOL4/string-case.sno
Normal file
26
Task/String-case/SNOBOL4/string-case.sno
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
define('uc(str)') :(uc_end)
|
||||
uc uc = replace(str,&lcase,&ucase) :(return)
|
||||
uc_end
|
||||
|
||||
define('lc(str)') :(lc_end)
|
||||
lc lc = replace(str,&ucase,&lcase) :(return)
|
||||
lc_end
|
||||
|
||||
define('ucfirst(str)ch') :(ucfirst_end)
|
||||
ucfirst str len(1) . ch = uc(ch)
|
||||
ucfirst = str :(return)
|
||||
ucfirst_end
|
||||
|
||||
define('swapc(str)') :(swapc_end)
|
||||
swapc str = replace(str,&ucase &lcase, &lcase &ucase)
|
||||
swapc = str :(return)
|
||||
swapc_end
|
||||
|
||||
* # Test and display
|
||||
str = 'alphaBETA'
|
||||
output = str
|
||||
output = lc(str)
|
||||
output = uc(str)
|
||||
output = ucfirst(str)
|
||||
output = swapc(str)
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue