String case: Difference between revisions

Add Ecstasy example
(Add Ecstasy example)
 
(46 intermediate revisions by 22 users not shown)
Line 20:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V s = ‘alphaBETA’
print(s.uppercase())
print(s.lowercase())</langsyntaxhighlight>
 
{{out}}
Line 34:
uppercase can be performed with a simple 'OR' with blank character (X'40'), in the same way
lowercase can be performed with a 'AND' with character 191 (X'BF').
<langsyntaxhighlight lang="360asm">UCASE CSECT
USING UCASE,R15
MVC UC,PG
Line 48:
LC DS CL(L'PG)
YREGS
END UCASE</langsyntaxhighlight>
{{out}}
<pre>
Line 58:
but now EBCDIC coding with alphabetic in 3 sequences, makes things a bit longer to create
translation tables.
<langsyntaxhighlight lang="360asm">UCASE CSECT
USING UCASE,R15
MVC UC,PG
Line 88:
ORG
YREGS
END UCASE</langsyntaxhighlight>
{{out}}
<pre>
Line 97:
 
=={{header|4D}}==
<langsyntaxhighlight lang="4d">$string:="alphaBETA"
$uppercase:=Uppercase($string)
$lowercase:=Lowercase($string)</langsyntaxhighlight>
 
=={{header|6502 Assembly}}==
 
<syntaxhighlight lang="text"> .lf case6502.lst
.cr 6502
.tf case6502.obj,ap1
Line 200:
.az -#13
;------------------------------------------------------
.en </langsyntaxhighlight>
Output:
<pre>
Line 209:
=={{header|68000 Assembly}}==
These algorithms work for any ASCII string. The implementation of actually printing the characters is left out, as it is not actually relevant to this task.
<langsyntaxhighlight lang="68000devpac">UpperCase:
;input: A0 = pointer to the string's base address.
;alters the string in-place.
 
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
CMP.B #'a',D0 ;compare to ascii code for a
BCS UpperCase.overhead ;if less than a, keep looping.
 
CMP.B #'z',D0 ;compare to ascii code for z
BHI Uppercase.overhead ;if greater than z, keep looping
 
AND.B #%1101111,D0 ;this "magic constant" turns lower case to upper case, since they're always 32 apart.
.overhead:
MOVE.B D0,(A0)+ ;store the letter back and increment the pointer.
;If this isn't an alphabetical character, D0 won't change and this store won't affect the string at all.
;If it was a letter, it will have been changed to upper case before storing back.
 
BRA UpperCase ;next letter
 
.Terminated:
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LowerCase:
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
CMP.B #'A',D0 ;compare to ascii code for A
BCS LowerCase.overhead ;if less than A, keep looping.
 
CMP.B #'Z',D0 ;compare to ascii code for Z
BHI LowerCase .overhead ;if greater than Z, keep looping
 
OR.B #%00100000,D0 ;this "magic constant" turns upper case to lower case, since they're always 32 apart.
.overhead:
MOVE.B D0,(A0)+ ;store the result and get ready to read the next letter.
BRA LowerCase ;next letter
.Terminated:
Line 243 ⟶ 251:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToggleCase:
MOVE.B (A0)+,D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
 
Line 250 ⟶ 258:
 
CMP.B #'A',D1 ;compare to ascii code for A
BCS ToggleCaseoverhead ;if less than A, keep looping.
 
CMP.B #'Z',D1 ;compare to ascii code for Z
BHI ToggleCaseoverhead ;if greater than Z, keep looping
 
EOR.B #%00100000,D0 ;swaps the case of the letter
overhead:
 
MOVE.B D0,(A0)+ ;store the result
BRA ToggleCase ;next letter
.Terminated:
RTS</langsyntaxhighlight>
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="8080asm"> org 100h
jmp demo
;;; Convert CP/M string under [HL] to upper case
Line 298 ⟶ 307:
mvi c,9
jmp 5
str: db 'alphaBETA',13,10,'$'</langsyntaxhighlight>
 
{{out}}
Line 305 ⟶ 314:
ALPHABETA
alphabeta</pre>
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits <br> or android 64 bits with application Termux }}
<syntaxhighlight lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program strcase64.s */
 
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
/************************************/
/* Initialized data */
/************************************/
.data
szMessResult: .asciz "Result: \n"
szString: .asciz "alphaBETA"
szCarriageReturn: .asciz "\n"
szMessStart: .asciz "Program 64 bits start.\n"
/************************************/
/* UnInitialized data */
/************************************/
.bss
sBuffer: .skip 80
sBuffex1: .skip 80
/************************************/
/* code section */
/************************************/
.text
.global main
main: // entry of program
ldr x0,qAdrszMessStart
bl affichageMess
ldr x1,qAdrszString
ldr x3,qAdrsBuffer
ldr x4,qAdrsBuffex1
mov x6,#0b100000 // 1 -> bit 5
mov x2,#0
1:
ldrb w0,[x1,x2] // load byte of string
mov x5,x0
cmp x0,#'A' // select alpha characters lower or upper
blt 3f
cmp x0,#'z'
bgt 3f
cmp x0,#'Z'
ble 2f
cmp x0,#'a'
bge 2f
b 3f
2:
orr x0,x0,x6 // converion in lower case (1 -> bit 5)
bic x5,x0,x6 // converion in upper case (0 -> bit 5)
3:
strb w0,[x3,x2] // store lower character
strb w5,[x4,x2] // store upper character
cmp x0,#0 // end string ?
add x2,x2,#1 // increment index character
bne 1b // loop
 
 
ldr x0,qAdrszMessResult
bl affichageMess
ldr x0,qAdrsBuffer
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrsBuffex1
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
100: // standard end of the program
mov x0, #0 // return code
mov x8, #EXIT // request to exit program
svc 0 // perform the system call
qAdrszString: .quad szString
qAdrsBuffer: .quad sBuffer
qAdrsBuffex1: .quad sBuffex1
qAdrszMessResult: .quad szMessResult
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrszMessStart: .quad szMessStart
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeARM64.inc"
 
</syntaxhighlight>
{{Out}}
<pre>
Program 64 bits start.
Result:
alphabeta
ALPHABETA
</pre>
=={{header|Action!}}==
{{libheader|Action! Tool Kit}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "D2:CHARTEST.ACT" ;from the Action! Tool Kit
 
PROC UpperCase(CHAR ARRAY text,res)
Line 341 ⟶ 445:
PrintF("Upper-case string: ""%S""%E",upper)
PrintF("Lower-case string: ""%S""%E",lower)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/String_case.png Screenshot from Atari 8-bit computer]
Line 352 ⟶ 456:
=={{header|ActionScript}}==
 
<langsyntaxhighlight lang="actionscript">var string:String = 'alphaBETA';
var upper:String = string.toUpperCase();
var lower:String = string.toLowerCase();</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight lang="ada">with Ada.Characters.Handling, Ada.Text_IO;
use Ada.Characters.Handling, Ada.Text_IO;
 
Line 365 ⟶ 469:
Put_Line (To_Upper (S));
Put_Line (To_Lower (S));
end Upper_Case_String;</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
Line 372 ⟶ 476:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}}
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}}
<langsyntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #
 
# Demonstrate toupper and tolower for standard ALGOL 68
Line 402 ⟶ 506:
string to lower(t);
printf(($"lowercase: "gl$, t))
)</langsyntaxhighlight>
Output:
<pre>
Line 410 ⟶ 514:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% algol W doesn't have standard case conversion routines, this is one way %
% such facilities could be provided %
Line 451 ⟶ 555:
write( text( 0 // 40 ) );
 
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 459 ⟶ 563:
 
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="amazing hopper">
<lang Amazing Hopper>
#include <hopper.h>
 
Line 495 ⟶ 599:
{_X_} // put processed string into the stack...
back
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 538 ⟶ 642:
{{works with|APL}}
In the following example, puntuation is not covered. It is substituted by '*'.
<langsyntaxhighlight lang="apl">
AlphLower←'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'
AlphUpper←'ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ*'
Line 548 ⟶ 652:
AlphLower[AlphUpper⍳'I'm using APL!']
i*m using apl*
</syntaxhighlight>
</lang>
==={{header|APL (Dyalog)}}===
Dyalog APL has a system function for case conversion, <code>⎕C</code>. This is Unicode-aware and preserves punctuation. If called monadically, maps character arrays to lower case. If called with a left-hand argument of 1, maps character arrays to upper case.
<syntaxhighlight lang="apl">
<lang APL>
⎕C 'Πέτρος is using APL!'
πέτροσ is using apl!
1 ⎕C 'Πέτρος is using APL!'
ΠΈΤΡΟΣ IS USING APL!
</syntaxhighlight>
</lang>
 
Note: The I-Beam operator with code 819 is now deprecated in favor of the system function <code>⎕C</code>.
Line 565 ⟶ 669:
AppleScript lacks built in string case functions, but since OS X 10.10 (Yosemite version, Oct 2014) it has been possible to use ObjC Foundation class methods directly in AppleScript code.
 
<langsyntaxhighlight lang="applescript">use framework "Foundation"
 
-- TEST -----------------------------------------------------------------------
Line 625 ⟶ 729:
end script
end if
end mReturn</langsyntaxhighlight>
{{Out}}
<langsyntaxhighlight AppleScriptlang="applescript">{"alphabeta αβγδεζηθ", "Alphabeta Αβγδεζηθ", "ALPHABETA ΑΒΓΔΕΖΗΘ"}</langsyntaxhighlight>
 
=={{header|Arbre}}==
<langsyntaxhighlight lang="arbre">main():
uppercase('alphaBETA') + '\n' + lowercase('alphaBETA') + '\n' -> io</langsyntaxhighlight>
Output:
<pre>
Line 637 ⟶ 741:
alphabeta
</pre>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi <br> or android 32 bits with application Termux}}
<syntaxhighlight lang ARM Assembly>
/* ARM assembly Raspberry PI */
/* program strcase.s */
 
/************************************/
/* Constantes */
/************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../constantes.inc"
 
/************************************/
/* Initialized data */
/************************************/
.data
szMessResult: .asciz "Result: \n"
szString: .asciz "alphaBETA"
szCarriageReturn: .asciz "\n"
szMessStart: .asciz "Program 32 bits start.\n"
/************************************/
/* UnInitialized data */
/************************************/
.bss
sBuffer: .skip 80
sBuffer1: .skip 80
/************************************/
/* code section */
/************************************/
.text
.global main
main: @ entry of program
ldr r0,iAdrszMessStart
bl affichageMess
ldr r1,iAdrszString
ldr r3,iAdrsBuffer
ldr r4,iAdrsBuffer1
mov r6,#0b100000 @ 1 -> bit 5
mov r2,#0
1:
ldrb r0,[r1,r2] @ load byte of string
mov r5,r0
cmp r0,#'A' @ select alpha characters lower or upper
blt 3f
cmp r0,#'z'
bgt 3f
cmp r0,#'Z'
ble 2f
cmp r0,#'a'
bge 2f
b 3f
2:
orr r0,r0,r6 @ converion in lower case (1 -> bit 5)
bic r5,r0,r6 @ converion in upper case (0 -> bit 5)
3:
strb r0,[r3,r2] @ store lower character
strb r5,[r4,r2] @ store upper character
cmp r0,#0 @ end string ?
add r2,r2,#1 @ increment index character
bne 1b @ loop
 
 
ldr r0,iAdrszMessResult
bl affichageMess
ldr r0,iAdrsBuffer
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrsBuffer1
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
100: @ standard end of the program
mov r0, #0 @ return code
mov r7, #EXIT @ request to exit program
swi 0 @ perform the system call
iAdrszString: .int szString
iAdrsBuffer: .int sBuffer
iAdrsBuffer1: .int sBuffer1
iAdrszMessResult: .int szMessResult
iAdrszCarriageReturn: .int szCarriageReturn
iAdrszMessStart: .int szMessStart
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language ARM assembly*/
.include "../affichage.inc"
 
</syntaxhighlight>
{{Out}}
<pre>
Program 32 bits start.
Result:
alphabeta
ALPHABETA
</pre>
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">str: "alphaBETA"
 
print ["uppercase :" upper str]
print ["lowercase :" lower str]
print ["capitalize :" capitalize str]</langsyntaxhighlight>
 
{{out}}
Line 653 ⟶ 852:
=={{header|AutoHotkey}}==
 
<langsyntaxhighlight lang="autohotkey">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"</langsyntaxhighlight>
 
=={{header|AutoIt}}==
 
<langsyntaxhighlight lang="autoit">$sString = "alphaBETA"
$sUppercase = StringUpper($sString) ;"ALPHABETA"
$sLowercase = StringLower($sString) ;"alphabeta"</langsyntaxhighlight>
 
=={{header|Avail}}==
 
<langsyntaxhighlight Availlang="avail">Print: uppercase "alphaBETA";
Print: lowercase "alphaBETA";</langsyntaxhighlight>
 
=={{header|AWK}}==
 
<langsyntaxhighlight lang="awk">BEGIN {
a = "alphaBETA";
print toupper(a), tolower(a)
}</langsyntaxhighlight>
 
Capitalize:
<langsyntaxhighlight lang="awk">BEGIN {
a = "alphaBETA";
print toupper(substr(a, 1, 1)) tolower(substr(a, 2))
}</langsyntaxhighlight>
 
=={{header|BASIC}}==
{{works with|QBasic}}
<langsyntaxhighlight lang="qbasic">s$ = "alphaBETA"
PRINT UCASE$(s$)
PRINT LCASE$(s$)</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
<langsyntaxhighlight ApplesoftBasiclang="applesoftbasic">S$ = "alphaBETA"
 
UP$ = "" : FOR I = 1 TO LEN(S$) : C = ASC(MID$(S$, I, 1)) : UP$ = UP$ + CHR$(C - (C > 96 AND C < 123) * 32) : NEXT I : ? UP$
 
LO$ = "" : FOR I = 1 TO LEN(S$) : C = ASC(MID$(S$, I, 1)) : LO$ = LO$ + CHR$(C + (C > 64 AND C < 91) * 32) : NEXT I : ? LO$</langsyntaxhighlight>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="freebasic">s$ = "alphaBETA"
print "Original string: "; s$
print "To Lower case: "; lower(s$)
print "To Upper case: "; upper(s$)</syntaxhighlight>
 
==={{header|BBC BASIC}}===
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"STRINGLIB"
original$ = "alphaBETA"
Line 704 ⟶ 909:
PRINT "Lower case: " FN_lower(original$)
PRINT "Upper case: " FN_upper(original$)
PRINT "Title case: " FN_title(original$)</langsyntaxhighlight>
Output:
<pre>Original: alphaBETA
Line 711 ⟶ 916:
Title case: AlphaBETA</pre>
 
==={{header|CommodoreChipmunk BASICBasic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 s$ = "alphaBETA"
20 print "Original string: ";s$
30 print "To Lower case: ";lcase$(s$)
40 print "To Upper case: ";ucase$(s$)</syntaxhighlight>
 
==={{header|Commodore BASIC}}===
The example here is based on AppleSoft BASIC, however, Commodore machines have a slightly different interpretation of ASCII:
 
Line 725 ⟶ 936:
 
'''Code Example'''
<langsyntaxhighlight lang="commodorebasic">10 rem string case
15 rem rosetta code
20 s$="alphaBETA"
Line 738 ⟶ 949:
75 next i
80 print:print "Uppercase: ";up$
90 print "Lowercase: ";lo$</langsyntaxhighlight>
 
{{output}}
Line 751 ⟶ 962:
ready.
&#9608;</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Dim s As String = "alphaBETA"
Print UCase(s)
Print LCase(s)
Sleep</syntaxhighlight>
 
{{out}}
<pre>
ALPHABETA
alphabeta
</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">window 1
 
CFStringRef s = @"alphaBETA"
 
print s
print ucase(s)
print lcase(s)
 
HandleEvents</syntaxhighlight>
 
Output:
<pre>
alphaBETA
ALPHABETA
alphabeta
</pre>
 
==={{header|Gambas}}===
'''[https://gambas-playground.proko.eu/?gist=d45e91bee011314fd126dc53052b5386 Click this link to run this code]'''
<syntaxhighlight lang="gambas">Public Sub Main()
Dim sString As String = "alphaBETA "
 
Print UCase(sString)
Print LCase(sString)
 
End</syntaxhighlight>
Output:
<pre>
ALPHABETA
alphabeta
</pre>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 INPUT PROMPT "String: ":TX$
110 PRINT "Lower case: ";LCASE$(TX$)
120 PRINT "Upper case: ";UCASE$(TX$)</langsyntaxhighlight>
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
<lang lb>
{{works with|Run BASIC}}
<syntaxhighlight lang="lb">
input$ ="alphaBETA"
 
Line 766 ⟶ 1,026:
 
end
</syntaxhighlight>
</lang>
 
==={{header|PureBasic}}===
<langsyntaxhighlight PureBasiclang="purebasic">s$ = "alphaBETA"
upper$ = UCase(s$) ;uppercase
lower$ = LCase(s$) ;lowercase</langsyntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">s$ = "alphaBETA"
PRINT "Original string: "; s$
PRINT "To Lower case: "; LCASE$(s$)
PRINT "To Upper case: "; UCASE$(s$)</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
<lang runbasic>a$ ="alphaBETA"
{{works with|Liberty BASIC}}
<syntaxhighlight lang="runbasic">a$ ="alphaBETA"
print a$ '=> alphaBETA
print upper$(a$) '=> ALPHABETA
print lower$(a$) '=> alphabeta</langsyntaxhighlight>
 
==={{header|TI-83 BASIC}}===
Note: While lowercase letters are built in to every TI-83/4/+/SE calculator, typing in lowercase is disabled by default and you have to hack the calculator to type in lowercase. However, the calculator does not have to be hacked to simply display lowercase output from a program, so on non-hacked calculators this program will only be useful one-way. To get lowercase letters, you have to create a new program with "AsmPrgmFDCB24DEC9" as the text, and then execute it on the homescreen with Asm(prgmYOURPROGRAMNAME). Then press [ALPHA] twice.
 
==={{header|True BASIC}}===
<syntaxhighlight lang="qbasic">LET s$ = "alphaBETA"
PRINT "Original string: "; s$
PRINT "To Lower case: "; LCASE$(s$)
PRINT "To Upper case: "; UCASE$(s$)
END</syntaxhighlight>
 
==={{header|Visual Basic}}===
{{works with|Visual Basic|VB6 Standard}}
<syntaxhighlight lang="vb">Sub Main()
Const TESTSTRING As String = "alphaBETA"
Debug.Print "initial = " _
& TESTSTRING
Debug.Print "uppercase = " _
& UCase(TESTSTRING)
Debug.Print "lowercase = " _
& LCase(TESTSTRING)
Debug.Print "first letter capitalized = " _
& StrConv(TESTSTRING, vbProperCase)
Debug.Print "length (in characters) = " _
& CStr(Len(TESTSTRING))
Debug.Print "length (in bytes) = " _
& CStr(LenB(TESTSTRING))
Debug.Print "reversed = " _
& StrReverse(TESTSTRING)
Debug.Print "first position of letter A (case-sensitive) = " _
& InStr(1, TESTSTRING, "A", vbBinaryCompare)
Debug.Print "first position of letter A (case-insensitive) = " _
& InStr(1, TESTSTRING, "A", vbTextCompare)
Debug.Print "concatenated with '123' = " _
& TESTSTRING & "123"
End Sub</syntaxhighlight>
{{out}}
<pre>initial = alphaBETA
uppercase = ALPHABETA
lowercase = alphabeta
first letter capitalized = Alphabeta
length (in characters) = 9
length (in bytes) = 18
reversed = ATEBahpla
first position of letter A (case-sensitive) = 9
first position of letter A (case-insensitive) = 1
concatenated with '123' = alphaBETA123</pre>
 
==={{header|Visual Basic .NET}}===
{{works with|Visual Basic|2008}}
<langsyntaxhighlight lang="vbnet">' Define 's'
Dim s AS String = "alphaBETA"
 
Line 792 ⟶ 1,106:
 
' Change 's' to Lower Case.
s = s.ToLower()</langsyntaxhighlight>
 
<langsyntaxhighlight lang="ti83b">:"ABCDEFGHIJKLMNOPQRSTUVWXYZ"→Str9
:"abcdefghijklmnopqrstuvwxyz"→Str0
:Input ">",Str1
Line 811 ⟶ 1,125:
:End
:sub(Str1,2,length(Str1)-2)→Str1
:Pause Str1</langsyntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="xbasic">PROGRAM "StringCase"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
s$ = "alphaBETA"
PRINT "Original string: "; s$
PRINT "To Lower case: "; LCASE$(s$)
PRINT "To Upper case: "; UCASE$(s$)
 
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="freebasic">s$ = "alphaBETA"
print "Original string: ", s$
print "To Lower case: ", lower$(s$)
print "To Upper case: ", upper$(s$)</syntaxhighlight>
 
=={{header|BCPL}}==
<langsyntaxhighlight BCPLlang="bcpl">get "libhdr"
 
// Check whether a character is an upper or lowercase letter
Line 839 ⟶ 1,175:
writef("Uppercase: %S*N", strtoupper(s))
writef("Lowercase: %S*N", strtolower(s))
$)</langsyntaxhighlight>
{{out}}
<pre> String: alphaBETA
Uppercase: ALPHABETA
Lowercase: alphabeta</pre>
 
 
=={{header|Beef}}==
<syntaxhighlight lang="csharp">
using System;
 
namespace StringCase
{
class Program
{
public static void Main()
{
String input = scope .("alphaBETA");
input.ToUpper();
Console.WriteLine(input);
input.ToLower();
Console.WriteLine(input);
}
}
}
</syntaxhighlight>
{{out}}
<pre>ALPHABETA
alphabeta</pre>
 
=={{header|Befunge}}==
{{works with|befungee}}
Converts to uppercase only; lowercase is done in a similar way so I chose not to add it.
<langsyntaxhighlight Befungelang="befunge">"ATEBahpla" > : #v_ 25* , @ >48*-v
> :: "`"` \"{"\` * | > , v
> ^
^ <</langsyntaxhighlight>
 
=={{header|BQN}}==
Both idioms are from BQNcrate. For reference, <code>⍋</code> in both examples performs a binary search to check if the characters are in the respective alphabet range. Based on that, the correct number is added at those locations to change case.
<syntaxhighlight lang="bqn">Upr ← -⟜(32×1="a{"⊸⍋) # Uppercase ASCII text
Lwr ← +⟜(32×1="A["⊸⍋) # Lowercase ASCII text</syntaxhighlight>
<syntaxhighlight> str ← "alphaBETA"
"alphaBETA"
Upr str
"ALPHABETA"
Lwr str
"alphabeta"</syntaxhighlight>
 
=={{header|Bracmat}}==
The functions <code>upp$</code> and <code>low$</code> assume that strings are UTF-8 encoded, but if a string is not valid UTF-8, it is assumed the string is ISO-8859-1. Case conversion is not restricted to the Latin alphabet, but extends to all alphabets that have upper and lower case characters.
<langsyntaxhighlight lang="bracmat"> "alphaBETA":?s
& out$str$(upp$!s \n low$!s)</langsyntaxhighlight>
Output:
<pre>ALPHABETA
Line 863 ⟶ 1,234:
=={{header|Burlesque}}==
 
<langsyntaxhighlight lang="burlesque">
blsq ) "alphaBETA"^^zz\/ZZ
"ALPHABETA"
"alphabeta"
</syntaxhighlight>
</lang>
 
=={{header|C}}==
The <tt>tolower</tt> and <tt>toupper</tt> functions are locale-aware.
<langsyntaxhighlight lang="c">/* Demonstrate toupper and tolower for
standard C strings.
This does not work for multibyte character sets. */
Line 906 ⟶ 1,277:
printf("lowercase: %s\n", t);
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">
class Program
{
Line 933 ⟶ 1,304:
Console.WriteLine("Converted: {0}", newStr);
}
}</langsyntaxhighlight>
 
Title case is a little different:
<langsyntaxhighlight lang="csharp">System.Console.WriteLine(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase("exAmpLe sTrinG"));</langsyntaxhighlight>
 
=={{header|C++}}==
Line 945 ⟶ 1,316:
This method does the transform in-place. Alternate methods might return a new copy or use a stream manipulator.
 
<langsyntaxhighlight lang="cpp">#include <algorithm>
#include <string>
#include <cctype>
Line 965 ⟶ 1,336:
str.begin(),
(int(*)(int)) std::tolower);
}</langsyntaxhighlight>
 
Here is sample usage code:
 
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
 
Line 980 ⟶ 1,351:
cout << foo << endl;
return 0;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="lisp">(def string "alphaBETA")
(println (.toUpperCase string))
(println (.toLowerCase string))</langsyntaxhighlight>
 
=={{header|CMake}}==
<langsyntaxhighlight lang="cmake">string(TOUPPER alphaBETA s)
message(STATUS "Uppercase: ${s}")
string(TOLOWER alphaBETA s)
message(STATUS "Lowercase: ${s}")</langsyntaxhighlight>
 
<pre>-- Uppercase: ALPHABETA
Line 998 ⟶ 1,369:
=={{header|COBOL}}==
===Standard-compliant Methods===
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. string-case-85.
 
Line 1,027 ⟶ 1,398:
 
GOBACK
.</langsyntaxhighlight>
 
===Compiler Extensions===
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. string-case-extensions.
 
Line 1,061 ⟶ 1,432:
 
GOBACK
.</langsyntaxhighlight>
 
=={{header|ColdFusion}}==
 
converting a string literal
<langsyntaxhighlight lang="coldfusion"><cfset upper = UCase("alphaBETA")>
<cfset lower = LCase("alphaBETA")></langsyntaxhighlight>
 
converting the value of a variable
<langsyntaxhighlight lang="coldfusion"><cfset string = "alphaBETA">
<cfset upper = UCase(string)>
<cfset lower = LCase(string)></langsyntaxhighlight>
 
=={{header|Common Lisp}}==
You can use the ''string-upcase'' function to perform upper casing:
 
<langsyntaxhighlight lang="lisp">CL-USER> (string-upcase "alphaBETA")
"ALPHABETA"</langsyntaxhighlight>
 
and you can do lower casing by using ''string-downcase'':
 
<langsyntaxhighlight lang="lisp">CL-USER> (string-downcase "alphaBETA")
"alphabeta"</langsyntaxhighlight>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
<langsyntaxhighlight lang="oberon2">
MODULE AlphaBeta;
IMPORT StdLog,Strings;
Line 1,103 ⟶ 1,474:
 
END AlphaBeta.
</syntaxhighlight>
</lang>
Execute: ^Q AlphaBeta.Do<br/>
Output:
Line 1,110 ⟶ 1,481:
Lowercase:> alphabeta
</pre>
 
=={{header|Crystal}}==
<syntaxhighlight lang="crystal">"alphaBETA".downcase # => "alphabeta"
"alphaBETA".upcase # => "ALPHABETA"
 
"alphaBETA".capitalize # => "Alphabeta"</syntaxhighlight>
 
Fully works with all Unicode range.
 
<syntaxhighlight lang="crystal">"ĥåçýджк".upcase # => "ĤÅÇÝДЖК"</syntaxhighlight>
 
=={{header|D}}==
<langsyntaxhighlight lang="d">void main() {
import std.stdio, std.string;
 
Line 1,118 ⟶ 1,499:
s.toUpper.writeln;
s.toLower.writeln;
}</langsyntaxhighlight>
{{out}}
<pre>ALPHABETA
alphabeta</pre>
 
=={{header|Dart}}==
<syntaxhighlight lang="dart">String capitalize(String string) {
if (string.isEmpty) {
return string;
}
return string[0].toUpperCase() + string.substring(1);
}
 
void main() {
var s = 'alphaBETA';
print('Original string: $s');
print('To Lower case: ${s.toLowerCase()}');
print('To Upper case: ${s.toUpperCase()}');
print('To Capitalize: ${capitalize(s)}');
}</syntaxhighlight>
{{out}}
<pre>Original string: alphaBETA
To Lower case: alphabeta
To Upper case: ALPHABETA
To Capitalize: AlphaBETA</pre>
 
=={{header|DBL}}==
<syntaxhighlight lang="dbl">
<lang DBL>
OPEN (1,O,'TT:') ;open video
 
Line 1,134 ⟶ 1,535:
 
UPCASE STR
DISPLAY (1,STR,10) ;ALPHABETA</langsyntaxhighlight>
 
=={{header|Delphi}}[[Category:Object Pascal]]==
<langsyntaxhighlight lang="pascal">writeln(uppercase('alphaBETA'));
writeln(lowercase('alphaBETA'));</langsyntaxhighlight>
 
=={{header|DWScript}}==
<langsyntaxhighlight lang="delphi">PrintLn(UpperCase('alphaBETA'));
PrintLn(LowerCase('alphaBETA'));</langsyntaxhighlight>
 
=={{header|Dyalect}}==
 
<langsyntaxhighlight lang="dyalect">let str = "alphaBETA"
print("Lower case: ", str.Lower(), separator: "")
print("Upper case: ", str.Upper(), separator: "")
print("Capitalize: ", str.Capitalize(), separator: "")</langsyntaxhighlight>
 
=={{header|E}}==
<langsyntaxhighlight lang="e">["alphaBETA".toUpperCase(),
"alphaBETA".toLowerCase()]</langsyntaxhighlight>
 
=={{header|EasyLang}}==
EasyLang does not have string case functions. The functions provided below only work with ASCII.
<syntaxhighlight lang="easylang">
func$ toUpper s$ .
for c$ in strchars s$
code = strcode c$
if code >= 97 and code <= 122
code -= 32
.
res$ &= strchar code
.
return res$
.
func$ toLower s$ .
for c$ in strchars s$
code = strcode c$
if code >= 65 and code <= 90
code += 32
.
res$ &= strchar code
.
return res$
.
string$ = "alphaBETA"
print string$
print toUpper string$
print toLower string$
</syntaxhighlight>
{{out}}
<pre>
alphaBETA
ALPHABETA
alphabeta
</pre>
 
=={{header|EchoLisp}}==
EchoLisp includes the usual case conversion functions and the '''randcase''' function : random case
<langsyntaxhighlight lang="scheme">
(string-downcase "alphaBETA")
→ "alphabeta"
Line 1,169 ⟶ 1,605:
(string-randcase "alphaBETA")
→ "AlPHaBeTA"
</syntaxhighlight>
</lang>
 
=={{header|ECL}}==
<langsyntaxhighlight ECLlang="ecl">IMPORT STD; //Imports the Standard Library
 
STRING MyBaseString := 'alphaBETA';
Line 1,182 ⟶ 1,618:
OUTPUT (UpperCased);
OUTPUT (LowerCased);
OUTPUT (TitleCased);</langsyntaxhighlight>
 
=={{header|Ecstasy}}==
The methods on <code>String</code> are <code>toUppercase()</code> and <code>toLowercase()</code>:
 
<syntaxhighlight lang="ecstasy">
module test {
void run() {
@Inject Console console;
console.print($"{"alphaBETA".toLowercase()=}");
console.print($"{"alphaBETA".toUppercase()=}");
}
}
</syntaxhighlight>
 
{{out}}
<pre>
x$ xec test
"alphaBETA".toLowercase()=alphabeta
"alphaBETA".toUppercase()=ALPHABETA
</pre>
 
=={{header|Elena}}==
ELENA 46.x:
<langsyntaxhighlight lang="elena">import system'culture;
public program()
Line 1,192 ⟶ 1,648:
string s1 := "alphaBETA";
// Alternative 1
console.writeLine(s1.lowerCase());
console.writeLine(s1.upperCase());
// Alternative 2
console.writeLine(s1.toLower(currentLocale));
console.writeLine(s1.toUpper(currentLocale));
console.readChar()
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
The String module provides the following functions:
<langsyntaxhighlight lang="elixir">
String.downcase("alphaBETA")
# => alphabeta
Line 1,211 ⟶ 1,662:
String.capitalize("alphaBETA")
# => Alphabeta
</syntaxhighlight>
</lang>
As with most String functions in Elixir, these are fully compatible with Unicode.
<langsyntaxhighlight lang="elixir">
String.downcase("αΒ")
# => αβ
Line 1,220 ⟶ 1,671:
String.capitalize("αΒ")
# => Αβ
String.upcase("ß")
</lang>
# => SS
</syntaxhighlight>
 
=={{header|Elm}}==
<langsyntaxhighlight lang="elm">import String exposing (toLower, toUpper)
 
s = "alphaBETA"
lower = toLower s
upper = toUpper s</langsyntaxhighlight>
 
=={{header|EMal}}==
 
<syntaxhighlight lang="emal">
var samples = text["alphaBETA", "ação", "o'hare O'HARE o’hare don't", "Stroßbùrri", "ĥåçýджк", "DŽLjnj"]
for each var sample in samples
writeLine(" original : " + sample)
writeLine(" lower : " + sample.lower())
writeLine(" upper : " + sample.upper())
writeLine()
end
</syntaxhighlight>
{{out}}
<pre>
original : alphaBETA
lower : alphabeta
upper : ALPHABETA
 
original : ação
lower : ação
upper : AÇÃO
 
original : o'hare O'HARE o’hare don't
lower : o'hare o'hare o’hare don't
upper : O'HARE O'HARE O’HARE DON'T
 
original : Stroßbùrri
lower : stroßbùrri
upper : STROßBÙRRI
 
original : ĥåçýджк
lower : ĥåçýджк
upper : ĤÅÇÝДЖК
 
original : DŽLjnj
lower : džljnj
upper : DŽLJNJ
 
</pre>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">string:to_upper("alphaBETA").
string:to_lower("alphaBETA").</langsyntaxhighlight>
 
=={{header|Excel}}==
Take 3 cells, say A1,B1 and C1. In B1 type :
 
<langsyntaxhighlight lang="excel">
=LOWER(A1)
</syntaxhighlight>
</lang>
 
and in C1 :
 
<langsyntaxhighlight lang="excel">
=UPPER(A1)
</syntaxhighlight>
</lang>
 
For the stated input in A1, the result will be :
 
<syntaxhighlight lang="text">
alphaBETA alphabeta ALPHABETA
</syntaxhighlight>
</lang>
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
let s = "alphaBETA"
let upper = s.ToUpper()
let lower = s.ToLower()
</syntaxhighlight>
</lang>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">"alphaBETA" >lower ! "alphabeta"
"alphaBETA" >upper ! "ALPHABETA"
"alphaBETA" >title ! "Alphabeta"
"ß" >case-fold ! "ss"</langsyntaxhighlight>
 
=={{header|Falcon}}==
 
<langsyntaxhighlight lang="falcon">printl("alphaBETA".lower())
printl("alphaBETA".upper())</langsyntaxhighlight>
 
=={{header|Fantom}}==
 
<langsyntaxhighlight lang="fantom">
fansh> a := "alphaBETA"
alphaBETA
Line 1,284 ⟶ 1,776:
fansh> "BETAalpha".decapitalize // make sure first letter is not capital
bETAalpha
</syntaxhighlight>
</lang>
 
=={{header|Forth}}==
Line 1,312 ⟶ 1,804:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<langsyntaxhighlight lang="fortran"> program example
implicit none
Line 1,349 ⟶ 1,841:
end subroutine To_Lower
 
end program example</langsyntaxhighlight>
 
Functions could be used instead, especially with later compilers that enable lengths not fixed at compile time, but this involves copying the text about. By contrast, the subroutines alter the text in-place, though if something like <code>Utext = Uppercase(text)</code> is desired so that both versions are available, a subroutine is less convenient.
Line 1,355 ⟶ 1,847:
F90 introduced the intrinsic function i = I'''A'''CHAR(c), which returns the integer value of the position of character c ''in the'' '''ASCII''' character set, even if the processor's default character set is different, such as perhaps '''EBCDIC'''. Function ACHAR is the inverse. If the bit pattern of the character was not being interpreted as in the ASCII set, this will cause odd results, say on a system using EBCDIC or (on an ASCII-using cpu) for a file originating from an EBCDIC-using system. Some systems offer additional options to the file OPEN statement that enable character conversion between ASCII and EBCDIC, and there may also be options concerning big- and little-endian usage. But much will depend on the format of the data in the file. If the data are a mixture of text, integers, floating-point, ''etc.'' all in binary, there will be no hope for such simple translations.
 
For converting lower-case text to upper, the following will work both on an ASCII system and an EBCDIC system (or any other encodement), once it is compiled for that system: <langsyntaxhighlight Fortranlang="fortran"> SUBROUTINE UPCASE(TEXT)
CHARACTER*(*) TEXT
INTEGER I,C
Line 1,362 ⟶ 1,854:
IF (C.GT.0) TEXT(I:I) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"(C:C)
END DO
END</langsyntaxhighlight>
The INDEX function of course returning zero if the character is not found. Converting from upper to lower case is the obvious inverse and it might be worthwhile defining a MODULE with suitable named character constants to avoid repetition - one might hope the compiler will share duplicated constants rather than producing a fresh version every time, but it might not too. The repeated text scanning done by the INDEX function for each character of TEXT will of course be a lot slower. A still-more advanced compiler might be able to take advantage of special translation op-codes, on systems that offer them. If storage space is not at a premium a swifter method would be to create something like <code>CHARACTER*1 XLATUC(0:255)</code> with most entries being equal to their index, except for those corresponding to the lower case letters for which the value is the corresponding upper case letter. Then <langsyntaxhighlight Fortranlang="fortran"> DO I = 1,LEN(TEXT)
TEXT(I:I) = XLATUC(ICHAR(TEXT(I:I)))
END DO</langsyntaxhighlight>
 
Note that in EBCDIC the offset is not 32 but 64. Rather than using an undocumented "magic constant" such as 32, one could define <code>PARAMETER (HIC = ICHAR("A") - ICHAR("a"))</code> instead or just place such code in-line and have hope for the compiler. This would also handle the small detail that "A" > "a" in EBCDIC rather than ASCII's "A" < "a". But alas, in EBCDIC the letter codes are ''not'' contiguous (there are many non-letter symbols between "a" and "z" as well as between "A" and "Z"), so the bounds of "A" to "Z" will ''not'' isolate only letters for attack. And it was not just IBM mainframes that used various versions of EBCDIC, so also did Burroughs, among others.
Line 1,371 ⟶ 1,863:
Here a complete example, using functions, and as far as I can tell, will work also with EBCDIC:
 
<syntaxhighlight lang="fortran">
<lang Fortran>
module uplow
implicit none
Line 1,448 ⟶ 1,940:
 
end program doit
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Dim s As String = "alphaBETA"
Print UCase(s)
Print LCase(s)
Sleep</lang>
 
{{out}}
<pre>
ALPHABETA
alphabeta
</pre>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
a = "alphaBETA"
println[lc[a]]
println[uc[a]]
</syntaxhighlight>
</lang>
 
These functions use Unicode single- and multiple-character mapping tables and thus try to do the right thing with Unicode, possibly making the string longer in some cases:
<langsyntaxhighlight lang="frink">uc["Imbiß"] // Last char is \u00df</langsyntaxhighlight>
 
Produces:
Line 1,479 ⟶ 1,957:
As the Unicode standard for casing states, "it is important to note that no casing operations on strings are reversible:"
 
<langsyntaxhighlight lang="frink">lc[ uc["Imbiß"] ]</langsyntaxhighlight>
<pre>imbiss</pre>
 
=={{header|FutureBasicGAP}}==
<syntaxhighlight lang="gap">LowercaseString("alphaBETA");
<lang futurebasic>window 1
UppercaseString("alphaBETA");</syntaxhighlight>
 
=={{header|GDScript}}==
CFStringRef s = @"alphaBETA"
{{works with|Godot|4.0.2}}
 
<syntaxhighlight lang="gdscript">
print s
extends MainLoop
print ucase(s)
print lcase(s)
 
HandleEvents</lang>
 
func _process(_delta: float) -> bool:
Output:
var string: String = "alphaBETA"
<pre>
print(string.to_upper())
alphaBETA
print(string.to_lower())
ALPHABETA
alphabeta
</pre>
 
# Note: These will also add/remove underscores.
=={{header|Gambas}}==
print("to_camel_case: ", string.to_camel_case())
'''[https://gambas-playground.proko.eu/?gist=d45e91bee011314fd126dc53052b5386 Click this link to run this code]'''
print("to_pascal_case: ", string.to_pascal_case())
<lang gambas>Public Sub Main()
print("to_snake_case: ", string.to_snake_case())
Dim sString As String = "alphaBETA "
 
return true # Exit
Print UCase(sString)
</syntaxhighlight>
Print LCase(sString)
 
{{out}}
End</lang>
Output:
<pre>
ALPHABETA
alphabeta
to_camel_case: alphaBeta
to_pascal_case: AlphaBeta
to_snake_case: alpha_beta
</pre>
 
=={{header|GAP}}==
<lang gap>LowercaseString("alphaBETA");
UppercaseString("alphaBETA");</lang>
 
=={{header|GML}}==
<langsyntaxhighlight GMLlang="gml">#define cases
{
x = 'alphaBETA';
Line 1,527 ⟶ 2,001:
show_message(y);
show_message(z);
}</langsyntaxhighlight>
 
=={{header|Go}}==
Line 1,533 ⟶ 2,007:
 
It is Title() on the other hand, that capitalizes the first letter of each word. It identifies word boundaries and capitalizes first letters, leaving other letters unmodified. As of Go 1.2 though, the word breaking algorithm is not Unicode compliant.
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,560 ⟶ 2,034:
fmt.Println("Swapping case: ", // DzLjNJ
strings.Map(unicode.SimpleFold, s))
}</langsyntaxhighlight>
 
Output:
{{out}}
 
<pre>
string: alphaBETA len: 9 runes
Line 1,590 ⟶ 2,066:
Title words: O'Hare O'HARE O’hare Don'T
Swapping case: O'HARE o'hare O’HARE DON'T
</pre>
 
Go handles many Unicode characters upcasing well but fails for some like [https://en.wikipedia.org/wiki/%C3%9F ß] where it hasn't changed <code>ß</code> into <code>SS</code> (expected <code>STROSSBÙRRI</code>).
 
<syntaxhighlight lang="go">
package main
 
import (
"fmt"
"strings"
)
 
func main() {
a := "Stroßbùrri"
b := "ĥåçýджк"
fmt.Println(strings.ToUpper(a))
fmt.Println(strings.ToUpper(b))
}
}</syntaxhighlight>
 
{{out}}
 
<pre>
STROßBÙRRI
ĤÅÇÝДЖК
</pre>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">def str = 'alphaBETA'
 
println str.toUpperCase()
println str.toLowerCase()</langsyntaxhighlight>
 
Output:
Line 1,603 ⟶ 2,104:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.Char
 
s = "alphaBETA"
 
lower = map toLower s
upper = map toUpper s</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER str = "alphaBETA"
EDIT(Text=str, UpperCase=LEN(str))
EDIT(Text=str, LowerCase=LEN(str))
EDIT(Text=str, UpperCase=1) </langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">procedure main()
write(map("alphaBETA"))
write(map("alphaBETA",&lcase,&ucase))
end</langsyntaxhighlight>
 
=={{header|IDL}}==
Line 1,630 ⟶ 2,131:
=={{header|J}}==
Use standard utilities:
<langsyntaxhighlight lang="j"> toupper 'alphaBETA'
ALPHABETA
tolower 'alphaBETA'
alphabeta</langsyntaxhighlight>
 
or alternative definitions:
<langsyntaxhighlight lang="j">upper=: {&((65+i.26) +&32@[} i.256)&.(a.&i.)
lower=: {&((97+i.26) -&32@[} i.256)&.(a.&i.)</langsyntaxhighlight>
 
For example:
<langsyntaxhighlight lang="j"> upper 'alphaBETA'
ALPHABETA
lower 'alphaBETA'
alphabeta</langsyntaxhighlight>
 
=={{header|Java}}==
The ''String'' class offers the ''toUpperCase'' and ''toLowerCase'' methods.
<lang java>String str = "alphaBETA";
There is no title-case, alternate-case, or sentence-case methods.
<syntaxhighlight lang="java">
String string = "alphaBETA".toUpperCase();
</syntaxhighlight>
<syntaxhighlight lang="java">
String string = "alphaBETA".toLowerCase();
</syntaxhighlight>
 
<br />
Alternately
<syntaxhighlight lang="java">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 "ß"</langsyntaxhighlight>
 
You could also easily create a <tt>swapCase</tt> method using <tt>Character.isLowerCase()</tt>, <tt>Character.isUpperCase()</tt>, and <tt>Character.isLetter()</tt>.
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">alert( "alphaBETA".toUpperCase() );
alert( "alphaBETA".toLowerCase() );</langsyntaxhighlight>
 
Output:
Line 1,664 ⟶ 2,176:
 
{{works with|NJS| 0.2.5}}
<langsyntaxhighlight lang="javascript">var string = "alphaBETA";
var uppercase = string.toUpperCase();
var lowercase = string.toLowerCase();</langsyntaxhighlight>
 
=={{header|Joy}}==
<syntaxhighlight lang="joy">DEFINE
islower == ord 109.5 - abs 13 <;
isupper == ord 77.5 - abs 13 <;
tolower == [[isupper] [32 +] [] ifte] map;
toupper == [[islower] [32 -] [] ifte] map.
 
"alphaBETA" tolower.
"alphaBETA" toupper.</syntaxhighlight>
 
=={{header|jq}}==
'''Works with jq and gojq, the C and Go implementations of jq'''
 
If your version of jq does not have ascii_downcase and ascii_upcase, then you might want to use their definitions:
<langsyntaxhighlight lang="jq"># like ruby's downcase - only characters A to Z are affected
def ascii_downcase:
explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;
Line 1,676 ⟶ 2,200:
# like ruby's upcase - only characters a to z are affected
def ascii_upcase:
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;</lang>
</syntaxhighlight>
jq's regular expression functions have a "case insensitive" option that is often useful
when handling text outside the ASCII range, as is illustrated by the last example below.
Currently, however, there is no built-in case-conversion filter for Unicode characters in general.
 
'''Examples''':
<syntaxhighlight lang="jq">
<lang jq>"alphaBETA" | ascii_upcase
"alphaBETA" | ascii_upcase
#=> "ALPHABETA"
 
"alphaBETA" | ascii_downcase
#=> "alphabeta"</lang>
 
jq -n '"á" | test("Á";"i")' # case-insensitive search
#=> true
</syntaxhighlight>
 
=={{header|Jsish}}==
<langsyntaxhighlight lang="javascript">var msg = "alphaBETA";
;msg;
;msg.toUpperCase();
Line 1,692 ⟶ 2,226:
;msg.toTitle();
;msg.toLocaleUpperCase();
;msg.toLocaleLowerCase();</langsyntaxhighlight>
 
{{out}}
Line 1,704 ⟶ 2,238:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">julia> uppercase("alphaBETA")
"ALPHABETA"
 
julia> lowercase("alphaBETA")
"alphabeta"</langsyntaxhighlight>
 
Some letters like ß (U+00DF) are transformed to ẞ (U+1E9E) in Julia, instead of SS (2 𝗑 U+0053) as expected of the Unicode standard<ref>https://unicode.org/faq/casemap_charprop.html#11</ref>.
 
<syntaxhighlight lang="julia">
julia> a = 'ß'
'ß': Unicode U+00DF (category Ll: Letter, lowercase)
 
julia> uppercase(a)
'ẞ': Unicode U+1E9E (category Lu: Letter, uppercase)
</syntaxhighlight>
 
=={{header|K}}==
{{works with|Kona}}
<lang k>
<syntaxhighlight lang="k"> s:"alphaBETA"
upper:{i:_ic x; :[96<i; _ci i-32;_ci i]}'
lower:{i:_ic x; :[91>i; _ci i+32;_ci i]}' / for reference
upper s
"ALPHABETA"
lower s
"alphabeta"
</syntaxhighlight>
</lang>
 
{{works with|ngn/k}}
<syntaxhighlight lang=K>s:"alphaBETA"
upper: {`c$x+-32*(x>"`")*x<"{"}
lower: {`c$x+32*(x>"@")*x<"["}
lower:_: / built in
 
upper "This is a test."
"THIS IS A TEST."
lower "This is a test."
"this is a test."
lower s
"alphabeta"
upper s
"ALPHABETA"</syntaxhighlight>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
fun main(args: Array<String>) {
Line 1,730 ⟶ 2,289:
println(s.capitalize())
println(s.decapitalize())
}</langsyntaxhighlight>
 
{{out}}
Line 1,742 ⟶ 2,301:
=={{header|Lambdatalk}}==
Lambdatalk can take benefit from CSS rules.
<langsyntaxhighlight lang="scheme">
{span {@ style="text-transform:lowercase"} alphaBETA } -> alphabeta
{span {@ style="text-transform:uppercase"} alphaBETA } -> ALPHABETA
</syntaxhighlight>
</lang>
 
=={{header|Lang}}==
<syntaxhighlight lang="lang">
$s = alphaBETA
fn.println(fn.toUpper($s))
fn.println(fn.toLower($s))
</syntaxhighlight>
{{out}}
<pre>
ALPHABETA
alphabeta
</pre>
 
=={{header|Lasso}}==
<langsyntaxhighlight Lassolang="lasso">// Direct string return
'alphaBETA'->uppercase&
'alphaBETA'->lowercase&
Line 1,759 ⟶ 2,330:
local(tolower = 'alphaBETA')
#tolower->lowercase
#tolower</langsyntaxhighlight>
 
=={{header|Lingo}}==
Lingo has no case conversion functions, but for ASCII strings they can e.g. be implemented like this:
<langsyntaxhighlight lang="lingo">----------------------------------------
-- Lower to upper case (ASCII only)
-- @param {string} str
Line 1,791 ⟶ 2,362:
end repeat
return str
end</langsyntaxhighlight>
 
<langsyntaxhighlight lang="lingo">put toUpper("alphaBETA")
-- "ALPHABETA"
 
put toLower("alphaBETA")
-- "alphabeta"</langsyntaxhighlight>
 
=={{header|LiveCode}}==
<langsyntaxhighlight LiveCodelang="livecode">put upper("alphaBETA") && lower("alphaBETA")
ALPHABETA alphabeta</langsyntaxhighlight>
 
=={{header|Logo}}==
Line 1,808 ⟶ 2,379:
 
=={{header|Lua}}==
<langsyntaxhighlight Lualang="lua">str = "alphaBETA"
 
print( string.upper(str) )
print( string.lowerupper(str) )</lang> -- ALPHABETA
print( string.lower(str) ) -- alphabeta
 
print ( str:upper() ) -- ALPHABETA
print ( str:lower() ) -- alphabeta
</syntaxhighlight>
 
The [https://www.lua.org/manual/5.4/manual.html#6.4 string library] properly works only for ASCII and extended ASCII (depending on the locals) ranges but not for Unicode.
 
<syntaxhighlight lang="lua">print ( string.upper("ação") ) -- returns AçãO instead of AÇÃO
print ( string.upper("ĥåçýджк") ) -- returns ĥåçýджк instead of ĤÅÇÝДЖК
</syntaxhighlight>
 
=={{header|M2000 Interpreter}}==
 
<syntaxhighlight lang="m2000 interpreter">
Module stringcase {
string s="alphaBETA", s1=s, c="!@@@@<"
print ucase$(s)="ALPHABETA"
print lcase$(s)="alphabeta"
s=str$(s+"ΑΛΦΑ", 1032) ' convert from utf16le to ansi 1032, and enpand to utf16LE as locale 1033
print s="alphaBETAÁËÖÁ"
// trait as utfLE16 but for character code from 0 to 255, and return based on locale 1033
print lcase$(s, 1033)="alphabetaáëöá"
// trait as utfLE16 but for character code from 0 to 255, and return based on locale 1032
print lcase$(s, 1032)="alphabetaαλφα"
print lcase$(s1+"ΑΛΦΑ")="alphabetaαλφα"
print str$(s1, ">")="ALPHABETA"
print str$(s1, "<")="alphabeta"
print str$(s1, c)="beta"
}
stringcase
</syntaxhighlight>
{{out}}
<pre>
True
True
True
True
True
True
True
True
True
</pre>
 
=={{header|M4}}==
<langsyntaxhighlight M4lang="m4">define(`upcase', `translit(`$*', `a-z', `A-Z')')
define(`downcase', `translit(`$*', `A-Z', `a-z')')
 
define(`x',`alphaBETA')
upcase(x)
downcase(x)</langsyntaxhighlight>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">str := "alphaBETA";
StringTools:-UpperCase(str);
StringTools:-LowerCase(str);</langsyntaxhighlight>
produces
<pre> alphabeta</pre>
Line 1,829 ⟶ 2,444:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">str="alphaBETA";
ToUpperCase[str]
ToLowerCase[str]</langsyntaxhighlight>
{{out}}
<pre>ALPHABETA
Line 1,837 ⟶ 2,452:
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight MATLABlang="matlab">>> upper('alphaBETA')
 
ans =
Line 1,847 ⟶ 2,462:
ans =
 
alphabeta</langsyntaxhighlight>
 
=={{header|Maxima}}==
<langsyntaxhighlight Maximalang="maxima">supcase('alphaBETA');
sdowncase('alphaBETA');</langsyntaxhighlight>
 
=={{header|MAXScript}}==
Requires MAX 2008
<langsyntaxhighlight lang="maxscript">str = "alphaBETA"
print (toUpper str)
print (toLower str)</langsyntaxhighlight>
 
=={{header|Mercury}}==
Line 1,863 ⟶ 2,478:
only affect unaccented Latin characters.
 
<syntaxhighlight lang="text">:- module string_case.
:- interface.
 
Line 1,878 ⟶ 2,493:
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.</langsyntaxhighlight>
 
=={{header|Metafont}}==
We need to implement it, since it is not already given; the following code works only for ASCII or ASCII based encodings. (It could work anyway also for single byte encodings where letters are contiguous).
 
<langsyntaxhighlight lang="metafont">vardef isbetween(expr a, i, f) =
if string a:
if (ASCII(a) >= ASCII(i)) and (ASCII(a) <= ASCII(f)):
Line 1,916 ⟶ 2,531:
endfor
?
enddef;</langsyntaxhighlight>
 
<langsyntaxhighlight lang="metafont">message toupper("alphaBETA");
message tolower("alphaBETA");
 
end</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang="min">"alphaBETA" uppercase
"alphaBETA" lowercase
"alphaBETA" capitalize</langsyntaxhighlight>
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">mixedString = "alphaBETA"
print "Upper Case of " + mixedString + " is " + mixedString.upper
print "Lower Case of " + mixedString + " is " + mixedString.lower</langsyntaxhighlight>
{{out}}
<pre>
Line 1,938 ⟶ 2,553:
Lower Case of alphaBETA is alphabeta
</pre>
 
=={{header|MIPS Assembly}}==
These examples modify a string in place. <code>$a0</code> is assumed to contain a pointer to the string ''in RAM;'' writes to ROM will obviously not have the desired effect.
<syntaxhighlight lang="mips">ToUpper:
;input: $a0 = pointer to beginning of string
;clobbers: $t0,$t1,$t2
 
li $t1,'a'
li $t2,'z'
ToUpper_again:
 
lbu $t0,($a0)
nop
 
beqz $t0,ToUpper_done ;if char is null terminator, exit
nop
 
bltu $t0,$t1,ToUpper_overhead ;if char stored in $t0 < 'a', skip
nop
 
bgtu $t0,$t2,ToUpper_overhead ;if char stored in $t0 > 'z', skip
nop
 
 
andi $t0,$t0,0xDF ;otherwise, do the work.
sb $t0,($a0)
 
ToUpper_overhead:
addiu $a0,1
b ToUpper_again
nop
 
ToUpper_done:
jr ra
nop
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToLower:
;input: $a0 = pointer to beginning of string
;clobbers: $t0,$t1,$t2
 
li $t1,'A'
li $t2,'Z'
ToLower_again:
 
lbu $t0,($a0)
nop
 
beqz $t0,ToUpper_done ;not a typo, I did this to save space.
nop
 
bltu $t0,$t1,ToLower_overhead ;if char stored in $t0 < 'a', skip
nop
 
bgtu $t0,$t2,ToLower_overhead ;if char stored in $t0 > 'z', skip
nop
 
 
ori $t0,$t0,0x20
sb $t0,($a0)
 
ToLower_overhead:
addiu $a0,1
b ToLower_again
nop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToggleCase:
li $t1,'A'
li $t2,'Z'
lbu $t0,($a0)
nop
beqz $t0,ToggleCase_done
nop
bltu $t0,$t1,ToggleCase_next
nop
bleu $t0,$t2,ToggleCase_Xor
nop
ToggleCase_next:
addiu $t1,0x20 ;li $t1,'a'
addiu $t2,0x20 ;li $t2,'z'
bltu $t0,$t1,ToggleCase_overhead
nop
bgtu $t0,$t2,ToggleCase_overhead
nop
ToggleCase_Xor:
xori $t0,$t0,0x20
sb $t0,($a0)
ToggleCase_overhead:
addiu $a0,1
b ToggleCase
nop
ToggleCase_done:
jr ra
nop</syntaxhighlight>
{{out}}
<pre>
alphaBETA ;original
ALPHABETA ;uppercase
alphabeta ;lowercase
ALPHAbeta ;toggled</pre>
 
=={{header|mIRC Scripting Language}}==
<langsyntaxhighlight lang="mirc">echo -ag $upper(alphaBETA)
echo -ag $lower(alphaBETA)</langsyntaxhighlight>
 
=={{header|Modula-3}}==
<langsyntaxhighlight lang="modula3">MODULE TextCase EXPORTS Main;
 
IMPORT IO, Text, ASCII;
Line 1,973 ⟶ 2,692:
IO.Put(Upper("alphaBETA\n"));
IO.Put(Lower("alphaBETA\n"));
END TextCase.</langsyntaxhighlight>
Output:
<pre>
Line 1,981 ⟶ 2,700:
 
=={{header|MUMPS}}==
<syntaxhighlight lang="mumps">
<lang MUMPS>
STRCASE(S)
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Line 1,989 ⟶ 2,708:
WRITE !,"Lower: "_$TRANSLATE(S,UP,LO)
QUIT
</syntaxhighlight>
</lang>
Output:<pre>
USER>DO STRCASE^ROSETTA("alphaBETA")
Line 1,999 ⟶ 2,718:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">string = "alphaBETA"
 
println upper(string)
println lower(string)</langsyntaxhighlight>
 
=={{header|Nemerle}}==
<langsyntaxhighlight Nemerlelang="nemerle">using System.Console;
using System.Globalization;
 
Line 2,019 ⟶ 2,738:
 
}
}</langsyntaxhighlight>
 
=={{header|NetRexx}}==
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
 
options replace format comments java crossref savelog symbols
Line 2,031 ⟶ 2,750:
say abc.lower
say abc.upper(1, 1) -- capitalize 1st character
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
<lang NewLISP>
(upper-case "alphaBETA")
(lower-case "alphaBETA")
</syntaxhighlight>
</lang>
 
=={{header|Nial}}==
<langsyntaxhighlight lang="nial">toupper 'alphaBETA'
=ALPHABETA
tolower 'alphaBETA'
=alphabeta</langsyntaxhighlight>
 
=={{header|Nim}}==
In the following example, we use the ASCII version of the procedures to convert to lower case, to convert to upper case or to capitalize. In module “unicode” there exists also three procedures "toLower", "toUpper" and "capitalize" which can do the same thing for UTF-8 encoded strings.
 
<langsyntaxhighlight lang="nim">import strutils
 
var s: string = "alphaBETA_123"
Line 2,054 ⟶ 2,773:
echo s, " as lower case: ", toLowerAscii(s)
echo s, " as capitalized: ", capitalizeAscii(s)
echo s, " as normal case: ", normalize(s) # to lower case without underscores.</langsyntaxhighlight>
{{out}}
 
Line 2,061 ⟶ 2,780:
alphaBETA_123 as capitalized: AlphaBETA_123
alphaBETA_123 as normal case: alphabeta123</pre>
 
Even with the Unicode specialized procedure, Nim doesn't handle all character correctly. For example, it fails for some characters like [https://en.wikipedia.org/wiki/%C3%9F ß] where it hasn't changed <code>ß</code> into <code>SS</code> (expected <code>STROSSBÙRRI</code>)<ref>https://unicode.org/faq/casemap_charprop.html#11</ref>.
 
<syntaxhighlight lang="nim">
import unicode
var a: string = "Stroßbùrri"
var b: string = "ĥåçýджк"
echo a.toUpper
echo b.toUpper
</syntaxhighlight>
 
{{out}}
 
<pre>
STROßBÙRRI
ĤÅÇÝДЖК
</pre>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">
string := "alphaBETA";
string->ToUpper()->PrintLine();
string->ToLower()->PrintLine();
</syntaxhighlight>
</lang>
 
=={{header|Objective-C}}==
{{works with|GNUstep}}
{{works with|Cocoa}}
<langsyntaxhighlight lang="objc">NSLog(@"%@", @"alphaBETA".uppercaseString);
NSLog(@"%@", @"alphaBETA".lowercaseString);
 
NSLog(@"%@", @"foO BAr".capitalizedString); // "Foo Bar"</langsyntaxhighlight>
 
=={{header|OCaml}}==
<langsyntaxhighlight lang="ocaml">let () =
let str = "alphaBETA" in
print_endline (String.uppercase_ascii str); (* ALPHABETA *)
Line 2,084 ⟶ 2,820:
 
print_endline (String.capitalize_ascii str); (* AlphaBETA *)
;;</langsyntaxhighlight>
 
=={{header|Octave}}==
<langsyntaxhighlight lang="octave">s = "alphaBETA";
slc = tolower(s);
suc = toupper(s);
disp(slc);
disp(suc);</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">"alphaBETA" toUpper
"alphaBETA" toLower</langsyntaxhighlight>
 
=={{header|OpenEdge/Progress}}==
<langsyntaxhighlight Progresslang="progress (OpenEdgeopenedge ABLabl)">caps("alphaBETA")
lc("alphaBETA")
</syntaxhighlight>
</lang>
 
=={{header|Oz}}==
Convert to upper/lower-case:
<langsyntaxhighlight lang="oz">declare
Str = "alphaBETA"
in
{System.showInfo {Map Str Char.toUpper}}
{System.showInfo {Map Str Char.toLower}}</langsyntaxhighlight>
 
Capitalize:
<langsyntaxhighlight lang="oz">declare
[StringX] = {Link ['x-oz://system/String.ozf']}
in
{System.showInfo {StringX.capitalize "alphaBETA"}} %% prints "AlphaBETA"</langsyntaxhighlight>
 
=={{header|Pascal}}==
 
<langsyntaxhighlight lang="pascal">
// Uppercase and Lowercase functions for a minimal standard Pascal
// where no library routines for these operations exist
Line 2,185 ⟶ 2,921:
Writeln('Lower case : ',lcase(ab));
END.
</syntaxhighlight>
</lang>
 
Demonstration:
Line 2,198 ⟶ 2,934:
=={{header|Peloton}}==
Iterating through the peerset
<langsyntaxhighlight lang="sgml"><@ ENU$$$LSTPSTLITLIT>UPP|
[<@ SAYELTLST>...</@>] <@ SAYHLPELTLST>...</@><@ DEFKEYELTLST>__SuperMacro|...</@>
<@ SAY&&&LIT>alphaBETA</@>
 
</@></langsyntaxhighlight>
 
Same code in padded-out, variable-length English dialect
<langsyntaxhighlight lang="sgml"><# ENUMERATION LAMBDA LIST PEERSET LITERAL LITERAL>UPP|
[<# SAY ELEMENT LIST>...</#>] <# SAY HELP ELEMENT LIST>...</#><# DEFINE KEYWORD ELEMENT LIST>__SuperMacro|...</#>
<# SAY SUPERMACRO LITERAL>alphaBETA</#>
 
</#></langsyntaxhighlight>
 
Output.
Line 2,231 ⟶ 2,967:
=={{header|Perl}}==
{{works with|Perl|5.x}}
<langsyntaxhighlight lang="perl">my $string = "alphaBETA";
print uc($string), "\n"; # => "ALPHABETA"
print lc($string), "\n"; # => "alphabeta"
Line 2,237 ⟶ 2,973:
 
print ucfirst($string), "\n"; # => "AlphaBETA"
print lcfirst("FOObar"), "\n"; # => "fOObar"</langsyntaxhighlight>
 
Also works in Perl 4 if the '''my''' is removed.
Line 2,243 ⟶ 2,979:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<langsyntaxhighlight Phixlang="phix">-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"alphaBETA"</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">upper</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">lower</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
There is also a bespoke convertCase function in demo\Edix\Edix.exw which accepts five operators: LOWER, UPPER, CAPITALISE, SENTENCE, and INVERT, which is obviously not part of the language, and a bit too long, messy, ugly, and unedifying, to bother reproducing here.
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">$str = "alphaBETA";
echo strtoupper($str), "\n"; // ALPHABETA
echo strtolower($str), "\n"; // alphabeta
Line 2,258 ⟶ 2,994:
echo lcfirst("FOObar"), "\n"; // fOObar
echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ
echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz</langsyntaxhighlight>
 
=={{header|Picat}}==
<langsyntaxhighlight Picatlang="picat">main =>
S = "alphaBETA",
println(to_uppercase(S)),
println(to_lowercase(S)).</langsyntaxhighlight>
 
{{out}}
Line 2,271 ⟶ 3,007:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(let Str "alphaBETA"
(prinl (uppc Str))
(prinl (lowc Str)) )</langsyntaxhighlight>
 
=={{header|Pike}}==
Line 2,279 ⟶ 3,015:
output will differ from run to run.
 
<langsyntaxhighlight Pikelang="pike">string s = "alphaBETA";
string s2 = "foo bar gazonk";
 
Line 2,288 ⟶ 3,024:
String.sillycaps(s2),
String.Elite.elite_string(s2));
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,303 ⟶ 3,039:
if sent raw wide strings.
 
<langsyntaxhighlight Pikelang="pike">#charset utf8
void main()
{
Line 2,310 ⟶ 3,046:
s, lower_case(s));
write( string_to_utf8(out) );
}</langsyntaxhighlight>
{{Out}}
<pre>
Line 2,318 ⟶ 3,054:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">
declare s character (20) varying initial ('alphaBETA');
 
put skip list (uppercase(s));
put skip list (lowercase(s));
</syntaxhighlight>
</lang>
 
<langsyntaxhighlight lang="pli">
/* An alternative to the above, which might be used if some */
/* non-standard conversion is required, is shown for */
Line 2,331 ⟶ 3,067:
put skip list ( translate(s, 'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ') );
</syntaxhighlight>
</lang>
 
=={{header|PL/SQL}}==
<langsyntaxhighlight lang="plsql">declare
vc VARCHAR2(40) := 'alphaBETA';
ivc VARCHAR2(40);
Line 2,343 ⟶ 3,079:
lvc := LOWER(vc); -- 'alphabeta'
uvc := UPPER(vc); -- 'ALPHABETA'
end; </langsyntaxhighlight>
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Put "alphaBeta" into a string.
Line 2,356 ⟶ 3,092:
Write the string to the console.
Wait for the escape key.
Shut down.</langsyntaxhighlight>
{{out}}
<pre>
Line 2,365 ⟶ 3,101:
 
=={{header|Pop11}}==
<langsyntaxhighlight lang="pop11">lvars str = 'alphaBETA';
lowertoupper(str) =>
uppertolower(str) =></langsyntaxhighlight>
 
=={{header|Potion}}==
<langsyntaxhighlight lang="potion">lowercase = (str) :
low = ("")
str length times (i) :
Line 2,394 ⟶ 3,130:
 
lowercase("alphaBETA") print
uppercase("alphaBETA") print</langsyntaxhighlight>
 
=={{header|Powerbuilder}}==
<langsyntaxhighlight lang="powerbuilder">string ls_string
ls_string = 'alphaBETA'
ls_string = Upper(ls_string)
ls_string = Lower(ls_string)</langsyntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight lang="powershell">
$string = 'alphaBETA'
$lower = $string.ToLower()
Line 2,410 ⟶ 3,146:
 
$lower, $upper, $title
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 2,419 ⟶ 3,155:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">s = "alphaBETA"
print s.upper() # => "ALPHABETA"
print s.lower() # => "alphabeta"
Line 2,429 ⟶ 3,165:
 
import string
print string.capwords("fOo bAR") # => "Foo Bar"</langsyntaxhighlight>
 
string.capwords() allows the user to define word separators, and by default behaves slightly differently than title().
 
<langsyntaxhighlight lang="python">print "foo's bar".title() # => "Foo'S Bar"
print string.capwords("foo's bar") # => "Foo's Bar"</langsyntaxhighlight>
 
=={{header|QB64}}==
<langsyntaxhighlight QB64lang="qb64">DIM s AS STRING * 9
s = "alphaBETA"
PRINT "The original string: " + s
PRINT ""
PRINT "Translated to lowercase: " + LCASE$(s)
PRINT "Translated to uppercase: " + UCASE$(s)</langsyntaxhighlight>
 
'''Optimized version:'''
Line 2,452 ⟶ 3,188:
* PRINT does not need empty quotes to print a blank line.
* Semi-colons use less data than the concatenation (+) method.
<langsyntaxhighlight lang="vb">s$ = "alphaBETA"
PRINT "The original string: "; s$: PRINT
PRINT "Converted to lowercase: "; LCASE$(s$)
PRINT "Converted to uppercase: "; UCASE$(s$)</langsyntaxhighlight>
 
 
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ $ "" swap
witheach [ upper join ] ] is upper$ ( $ --> $ )
 
Line 2,468 ⟶ 3,204:
$ "PaTrIcK, I dOn'T tHiNk WuMbO iS a ReAl wOrD."
dup lower$ echo$ cr
upper$ echo$ cr</langsyntaxhighlight>
 
{{Out}}
Line 2,477 ⟶ 3,213:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r"> str <- "alphaBETA"
toupper(str)
tolower(str)</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight Racketlang="racket">#lang racket
(define example "alphaBETA")
 
Line 2,490 ⟶ 3,226:
;"alphabeta"
(string-titlecase example)
;"Alphabeta"</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 2,496 ⟶ 3,232:
In Raku, case modification is implemented as builtin subroutine or method:
 
<syntaxhighlight lang="raku" perl6line>my $word = "alpha BETA" ;
say uc $word; # all uppercase (subroutine call)
say $word.uc; # all uppercase (method call)
Line 2,504 ⟶ 3,240:
say $word.tclc; # first letter titlecase, rest lowercase
say $word.wordcase; # capitalize each word
</syntaxhighlight>
</lang>
Output:
<pre>ALPHA BETA
Line 2,513 ⟶ 3,249:
 
=={{header|Raven}}==
<langsyntaxhighlight lang="raven">'alphaBETA' upper
'alhpaBETA' lower</langsyntaxhighlight>
 
=={{header|REBOL}}==
<langsyntaxhighlight REBOLlang="rebol">print ["Original: " original: "alphaBETA"]
print ["Uppercase:" uppercase original]
print ["Lowercase:" lowercase original]</langsyntaxhighlight>
 
Output:
Line 2,528 ⟶ 3,264:
 
=={{header|Red}}==
<langsyntaxhighlight Redlang="red">str: "alphaBETA"
>> uppercase str
== "ALPHABETA"
Line 2,534 ⟶ 3,270:
== "alphabeta"
>> uppercase/part str 5
== "ALPHAbeta"</langsyntaxhighlight>
 
=={{header|Retro}}==
<langsyntaxhighlight Retrolang="retro">'alphaBETA s:to-upper s:put
'alphaBETA s:to-lower s:put</langsyntaxhighlight>
 
=={{header|REXX}}==
===with TRANSLATE BIF===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<langsyntaxhighlight lang="rexx">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*/</langsyntaxhighlight>
 
===with PARSE UPPER &amp; PARSE LOWER statements===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<langsyntaxhighlight lang="rexx">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.*/</langsyntaxhighlight>
 
===with UPPER &amp; LOWER BIFs===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<langsyntaxhighlight lang="rexx">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).*/</langsyntaxhighlight>
 
===with UPPER statement===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<langsyntaxhighlight lang="rexx">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.*/</langsyntaxhighlight>
 
===with capitalized words===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<langsyntaxhighlight lang="rexx">/*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.*/
Line 2,593 ⟶ 3,329:
end /*j*/
 
return substr($, 2) /*return the capitalized words. */</langsyntaxhighlight>
Some older REXXes don't have a &nbsp; '''changestr''' &nbsp; BIF, so one is included here &nbsp; ───► &nbsp; [[CHANGESTR.REX]]. <br>
 
Line 2,606 ⟶ 3,342:
===with case swap===
The following code will execute correctly in &nbsp; '''ASCII''' &nbsp; and &nbsp; '''EBCDIC.
<langsyntaxhighlight lang="rexx">/*REXX program swaps the letter case of a string: lower ──► upper & upper ──► lower.*/
abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase letters. */
abcU = translate(abc) /* " " " uppercase " */
Line 2,614 ⟶ 3,350:
say x
say y
/*stick a fork in it, we're all done. */</langsyntaxhighlight>
'''output'''
<pre>
Line 2,622 ⟶ 3,358:
 
===version 2===
<langsyntaxhighlight lang="rexx">
x='alphaBETA'; Say ' x='||x
Say 'three ways to uppercase'
Line 2,634 ⟶ 3,370:
l2=lower(x); Say ' l2='l2
parse lower var x l3; Say ' l3='l3
</syntaxhighlight>
</lang>
:Note: Parse options upper and lower not available in every Rexx
:Builtin functions upper and lower not available in every Rexx
Line 2,640 ⟶ 3,376:
 
For German input (considering umlaute) these will uppercase them:
<langsyntaxhighlight lang="rexx">
uppercase: /*courtesy Gerard Schildberger */
return translate(changestr("ß",translate(arg(1),'ÄÖÜ',"äöü"),'SS'))
Line 2,649 ⟶ 3,385:
a=changestr("ß",a,'SS') /* replace ß with SS */
return translate(a) /* translate lowercase letters */
</syntaxhighlight>
</lang>
Translation to lowercase is not similarly possible because of 'SS'->'ß' or -> 'ss' ??
<br>
Line 2,655 ⟶ 3,391:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
aString = "WELCOME TO THE ring programming language"
see lower(aString) + nl
see upper(aString) + nl
</syntaxhighlight>
</lang>
 
=={{header|RPL}}==
{{works with|HP|48}}
≪ 1 OVER SIZE '''FOR''' j
DUP j DUP SUB
'''IF''' DUP "a" < OVER "z" > OR '''THEN''' DROP
'''ELSE''' NUM 32 - CHR j SWAP REPL '''END'''
'''NEXT'''
≫ ≫ '<span style="color:blue">→UPPER</span>' STO
≪ 1 OVER SIZE '''FOR''' j
DUP j DUP SUB
'''IF''' DUP "A" < OVER "Z" > OR THEN DROP
'''ELSE''' NUM 32 + CHR j SWAP REPL '''END'''
'''NEXT'''
≫ ≫ '<span style="color:blue">→LOWER</span>' STO
 
"alphaBETA" <span style="color:blue">→UPPER</span>
"alphaBETA" <span style="color:blue">→LOWER</span>
{{out}}
<pre>
2: "ALPHABETA"
1: "alphabeta"
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">"alphaBETA".downcase # => "alphabeta"
"alphaBETA".upcase # => "ALPHABETA"
 
"alphaBETA".swapcase # => "ALPHAbeta"
"alphaBETA".capitalize # => "Alphabeta"</langsyntaxhighlight>
 
These methods used to affect ASCII letters A-Z and a-z only. From Ruby 2.4 onward however, these methods support Full Unicode case mapping, suitable for most languages, by default. (Options can be specified for Turkic, Lithuanian and ascii)
{{works with|Ruby| 2.4}}
<langsyntaxhighlight lang="ruby">'ĥåçýджк'.upcase # => "ĤÅÇÝДЖК"</langsyntaxhighlight>
 
=={{header|Rust}}==
{{works with|Rust| 1.3}}
<langsyntaxhighlight lang="rust">fn main() {
println!("{}", "jalapeño".to_uppercase()); // JALAPEÑO
println!("{}", "JALAPEÑO".to_lowercase()); // jalapeño
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight Scalalang="scala">val s="alphaBETA"
println(s.toUpperCase) //-> ALPHABETA
println(s.toLowerCase) //-> alphabeta
println(s.capitalize) //-> AlphaBETA
println(s.reverse) //-> ATEBahpla</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(define s "alphaBETA")
(list->string (map char-upcase (string->list s)))
(list->string (map char-downcase (string->list s)))</langsyntaxhighlight>
 
Using SRFI-13:
 
<langsyntaxhighlight lang="scheme">
> (define s "alphaBETA gammaDELTA")
> (string-upcase s) ;; turn all into upper case
Line 2,701 ⟶ 3,461:
> (string-titlecase s) ;; capitalise start of each word
"Alphabeta Gammadelta"
</syntaxhighlight>
</lang>
 
=={{header|Sed}}==
Piping through sed in bash:
 
<langsyntaxhighlight lang="bash">echo "alphaBETA" | sed 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'
echo "alphaBETA" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'</langsyntaxhighlight>
 
Other functions:
<langsyntaxhighlight lang="bash"># Invert case
echo "alphaBETA" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/'</langsyntaxhighlight>
 
GNU sed supports special sequences to change case:
<langsyntaxhighlight lang="bash">
# to uppercase
$ echo alphaBETA | sed 's/.*/\U&/'
Line 2,721 ⟶ 3,481:
$ echo alphaBETA | sed 's/.*/\L&/'
alphabeta
</syntaxhighlight>
</lang>
 
=={{header|Seed7}}==
Line 2,728 ⟶ 3,488:
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">
set letters to "alphaBETA"
put lowercase of letters // alphabeta
Line 2,743 ⟶ 3,503:
 
put letters //ALPHAbeta
</syntaxhighlight>
</lang>
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">say "alphaBETA".lc; #=> alphabeta
say "alphaBETA".uc; #=> ALPHABETA
say "alphaBETA".tc; #=> AlphaBETA
say "alpha BETA".wc; #=> Alpha Beta
say "alpha BETA".tc; #=> Alpha BETA
say "alpha BETA".tclc; #=> Alpha beta</langsyntaxhighlight>
 
=={{header|Simula}}==
<langsyntaxhighlight Simulalang="simula">TEXT soup, lower;
soup :- "alphaBETA";
lower :- LOWCASE(COPY(soup)); ! COPY, else soup is changed;
OutText("upper: "); OutText(UPCASE("alphaBETA"));
OutText(", lower: "); OutText(lower);
OutText(", soup: "); OutText(soup); Outimage;</langsyntaxhighlight>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">'alphaBETA' toLowercase.
'alphaBETA' toUppercase.</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">'ALPHAbeta' asUppercase "->'ALPHABETA' "
'ALPHAbeta' asLowercase "-> 'alphabeta' "</langsyntaxhighlight>
{{works with|Smalltalk/X}}
{{works with|VisualWorks Smalltalk}}
<langsyntaxhighlight lang="smalltalk">'alphabeta' asUppercaseFirst "-> 'Alphabeta' "</langsyntaxhighlight>
Unicode (notice, that this cannot be done simply with a straight forward "ch := ch -$a + $A" loop):
{{works with|Smalltalk/X}} (may work with other dialects too, but I have not verified)
<langsyntaxhighlight lang="smalltalk">'αβγω' asUppercase -> 'ΑΒΓΩ'
'ĥåçýджк' asUppercase "-> 'ĤÅÇÝДЖК'
'abcäöüáéíýıijńǵȅȇȉ' asUppercase -> 'ABCÄÖÜÁÉÍÝIIJŃǴȄȆȈ'</langsyntaxhighlight>
 
=={{header|SNOBOL4}}==
Line 2,781 ⟶ 3,541:
There are no standard Snobol libraries or case conversion built-ins. But case functions are easy to roll using the character class keywords. Native charset only.
<langsyntaxhighlight SNOBOL4lang="snobol4"> define('uc(str)') :(uc_end)
uc uc = replace(str,&lcase,&ucase) :(return)
uc_end
Line 2,806 ⟶ 3,566:
output = ucfirst(str)
output = swapc(str)
end</langsyntaxhighlight>
 
An alternative way of constructing the above that groups related functions together in a denser display:
 
<langsyntaxhighlight SNOBOL4lang="snobol4"> define('UC(STR)')
define('LC(STR)')
define('UCFIRST(STR)')
Line 2,827 ⟶ 3,587:
output = ucfirst(str)
output = swapc(str)
END</langsyntaxhighlight>
 
Output:
Line 2,835 ⟶ 3,595:
AlphaBETA
ALPHAbeta</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "stringcase" )
@( description, "Take the string 'alphaBETA', and demonstrate how to" )
@( description, "convert it to UPPER-CASE and lower-case. Use the" )
@( description, "default encoding of a string literal or plain ASCII if" )
@( description, "there is no string literal in your language. Show any" )
@( description, "additional case conversion functions (e.g. swapping" )
@( description, "case, capitalizing the first letter, etc.) that may be" )
@( description, "included in the library of your language. " )
@( category, "tutorials" )
@( author, "Ken O. Burtch" )
@( see_also, "http://rosettacode.org/wiki/String_case" );
pragma license( unrestricted );
 
pragma software_model( nonstandard );
pragma restriction( no_external_commands );
 
procedure stringcase is
s : constant string := "alphaBETA";
begin
? strings.to_upper( s );
? strings.to_lower( s );
? strings.to_proper( s );
end stringcase;</syntaxhighlight>
 
=={{header|SQL}}==
{{works with|MS SQL| 2005}}
<langsyntaxhighlight lang="sql">declare @s varchar(10)
set @s = 'alphaBETA'
print upper(@s)
print lower(@s)</langsyntaxhighlight>
 
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
With SQL only:
<langsyntaxhighlight lang="sql pl">
values upper('alphaBETA');
values lower('alphaBETA');
Line 2,852 ⟶ 3,639:
-- Within a SQL query.
select upper('alphaBETA') from sysibm.sysdummy1;
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,890 ⟶ 3,677:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">val strupr = String.map Char.toUpper;
val strlwr = String.map Char.toLower;</langsyntaxhighlight>
 
Test
Line 2,904 ⟶ 3,691:
Use '''[https://www.stata.com/help.cgi?f_strupper strupper]''' and '''strlower''' to change case of ASCII characters. Use '''[https://www.stata.com/help.cgi?f_ustrupper ustrupper]''' and '''ustrlower''' to change case of all Unicode letters.
 
<langsyntaxhighlight lang="stata">. scalar s="alphaBETA"
. di strupper(s)
ALPHABETA
. di strlower(s)
alphabeta</langsyntaxhighlight>
 
Notice there may be some difficulties with Unicode characters. In the following, the uppercase '''[https://en.wikipedia.org/wiki/Sigma sigma]''' is correctly converted back to the lowercase variant, but the '''[https://en.wikipedia.org/wiki/Iota_subscript iota subscript]''' is not.
 
<langsyntaxhighlight lang="stata">. scalar a="Ἐν ἀρχῇ ἐποίησεν ὁ θεὸς τὸν οὐρανὸν καὶ τὴν γῆν"
. scalar b=ustrupper(a)
. di b
ἘΝ ἈΡΧΗ͂Ι ἘΠΟΊΗΣΕΝ Ὁ ΘΕῸΣ ΤῸΝ ΟΥ̓ΡΑΝῸΝ ΚΑῚ ΤῊΝ ΓΗ͂Ν
. di ustrlower(b)
ἐν ἀρχῆι ἐποίησεν ὁ θεὸς τὸν οὐρανὸν καὶ τὴν γῆν</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Foundation
 
println("alphaBETA".uppercaseString)
println("alphaBETA".lowercaseString)
println("foO BAr".capitalizedString)</langsyntaxhighlight>
{{output}}
<pre>
Line 2,933 ⟶ 3,720:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">set string alphaBETA
 
# three built-in case conversion commands
Line 2,962 ⟶ 3,749:
 
swapcase Père ;# ==> pÈRE
swapcase_en Père ;# ==> pèRE</langsyntaxhighlight>
 
=={{header|Toka}}==
Line 2,980 ⟶ 3,767:
 
=={{header|Transd}}==
<langsyntaxhighlight Schemelang="scheme">#lang transd
 
MainModule: {
Line 2,988 ⟶ 3,775:
(lout (tolower s)))
)
}</langsyntaxhighlight>
{{out}}
<pre>
Line 2,996 ⟶ 3,783:
 
=={{header|TUSCRIPT}}==
<langsyntaxhighlight lang="tuscript">
$$ MODE TUSCRIPT,{}
string="alphaBETA"
Line 3,005 ⟶ 3,792:
PRINT uppercase1
PRINT uppercase2
</syntaxhighlight>
</lang>
Output:
<pre>
Line 3,017 ⟶ 3,804:
 
For System V tr:
<langsyntaxhighlight lang="bash">echo alphaBETA | tr '[a-z]' '[A-Z]' # => ALPHABETA
echo alphaBETA | tr '[A-Z]' '[a-z]' # => alphabeta</langsyntaxhighlight>
 
For [[BSD]] tr, [[GNU]] tr, or any [[POSIX]] system:
<langsyntaxhighlight lang="bash">echo alphaBETA | tr a-z A-Z # => ALPHABETA
echo alphaBETA | tr A-Z a-z # => alphabeta</langsyntaxhighlight>
 
System V has a different syntax, and requires square brackets around ranges. Portable scripts can use System V syntax; the other systems handle square brackets as literal characters, translating [ to [ and ] to ], which is harmless.
Line 3,029 ⟶ 3,816:
{{works with|bash}}
 
<langsyntaxhighlight lang="bash">s="alphaBETA"
echo ${s^^} # => ALPHABETA
echo ${s,,} # => alphabeta
echo ${s^} # => AlphaBETA</langsyntaxhighlight>
 
===Z Shell===
{{works with|zsh}}
 
<langsyntaxhighlight lang="bash">s="alphaBETA"
echo ${s:u} # => ALPHABETA
echo ${s:l} # => alphabeta</langsyntaxhighlight>
 
=={{header|Ursa}}==
<langsyntaxhighlight lang="ursa">out (lower "alphaBETA") endl console
out (upper "alphaBETA") endl console</langsyntaxhighlight>
 
=={{header|Ursala}}==
Case conversion functions aren't built in but can be defined using the
reification operator (-:) to construct a function from a list of pairs.
<langsyntaxhighlight Ursalalang="ursala">#import std
 
to_upper = * -:~& ~=`A-~p letters
Line 3,055 ⟶ 3,842:
#show+
 
examples = <to_upper 'alphaBETA',to_lower 'alphaBETA'></langsyntaxhighlight>
output:
<pre>ALPHABETA
Line 3,061 ⟶ 3,848:
 
=={{header|Vala}}==
<langsyntaxhighlight lang="vala">
string s = "alphaBeta";
// stores ALPHABETA to string
Line 3,067 ⟶ 3,854:
// stores alphabeta to string
string s_lower = s.down();
</syntaxhighlight>
</lang>
 
=={{header|VBA}}==
<langsyntaxhighlight VBlang="vb">Function StringCase()
Dim s As String
s = "alphaBETA"
Line 3,076 ⟶ 3,863:
Debug.Print LCase(s)
Debug.Print WorksheetFunction.Proper(s)
End Function</langsyntaxhighlight>
 
Output:
Line 3,084 ⟶ 3,871:
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vbscript">Dim MyWord
MyWord = UCase("alphaBETA") ' Returns "ALPHABETA"
MyWord = LCase("alphaBETA") ' Returns "alphabeta"</langsyntaxhighlight>
 
=={{header|Vedit macro language}}==
<langsyntaxhighlight lang="vedit">#1 = CP
IT("alphaBETA")
Case_Upper_Block(#1, CP)
Case_Lower_Block(#1, CP)</langsyntaxhighlight>
 
=={{header|VisualV Basic(Vlang)}}==
{{works with|Visual Basic|VB6 Standard}}
<lang vb>Sub Main()
Const TESTSTRING As String = "alphaBETA"
Debug.Print "initial = " _
& TESTSTRING
Debug.Print "uppercase = " _
& UCase(TESTSTRING)
Debug.Print "lowercase = " _
& LCase(TESTSTRING)
Debug.Print "first letter capitalized = " _
& StrConv(TESTSTRING, vbProperCase)
Debug.Print "length (in characters) = " _
& CStr(Len(TESTSTRING))
Debug.Print "length (in bytes) = " _
& CStr(LenB(TESTSTRING))
Debug.Print "reversed = " _
& StrReverse(TESTSTRING)
Debug.Print "first position of letter A (case-sensitive) = " _
& InStr(1, TESTSTRING, "A", vbBinaryCompare)
Debug.Print "first position of letter A (case-insensitive) = " _
& InStr(1, TESTSTRING, "A", vbTextCompare)
Debug.Print "concatenated with '123' = " _
& TESTSTRING & "123"
End Sub</lang>
{{out}}
<pre>initial = alphaBETA
uppercase = ALPHABETA
lowercase = alphabeta
first letter capitalized = Alphabeta
length (in characters) = 9
length (in bytes) = 18
reversed = ATEBahpla
first position of letter A (case-sensitive) = 9
first position of letter A (case-insensitive) = 1
concatenated with '123' = alphaBETA123</pre>
 
=={{header|Vlang}}==
{{trans|go}}
<syntaxhighlight lang="v (vlang)">fn show(s string) {
println('string: $s len: $s.len')
println('All upper case: ${s.to_upper()}')
Line 3,146 ⟶ 3,896:
show('DŽLjnj')
show("o'hare O'HARE o’hare don't")
}</langsyntaxhighlight>
Output:
<pre>
Line 3,172 ⟶ 3,922:
=={{header|Wren}}==
{{libheader|Wren-str}}
The 'Str' class supports the following methods:
<lang ecmascript>import "/str" for Str
 
# ''lower'' - converts all letters to lower case
var s = "alphaBETA"
# ''upper'' - converts all letters to upper case
System.print(Str.upper(s))
# ''capitalize'' - converts only the first letter to upper case
System.print(Str.lower(s))</lang>
# ''title'' - converts the first letter of each word to upper case
# ''swapCase'' - swaps the case of each letter
 
However, support is limited to letters which have both lower and upper case variants with codepoints < 256. This means that the lower case letters 'ß' and 'ÿ' are never changed by these methods. Although it would be possible to regard 'SS' as the upper case equivalent of 'ß', unfortunately this might not 'round-trip' and would not be compatible with the ''Char.upper'' method in any case. It has not therefore been done.
 
The 'Utf8' class recently acquired the first four of the above methods though with considerably wider (albeit still incomplete) Unicode coverage. In particular the upper case variants 'ẞ' and 'Ÿ' are now supported - the former was introduced into official German orthography in 2017 (though is optional) and, of course, now round-trips. Title case for 4 supported digraphs is automatically applied by the ''capitalize'' or ''title'' methods when they are the first character of the string (or, word, in the case of the latter).
<syntaxhighlight lang="wren">import "./str" for Str, Utf8
 
var strs = ["alphaBETA", "ação", "o'hare O'HARE o’hare don't"]
System.print("Using 'Str' class methods:")
for (s in strs) {
System.print(" original : %(s)")
System.print(" lower : %(Str.lower(s))")
System.print(" upper : %(Str.upper(s))")
System.print(" capitalize : %(Str.capitalize(s))")
System.print(" title : %(Str.title(s))")
System.print(" swapCase : %(Str.swapCase(s))")
System.print()
}
var strs2 = ["Stroßbùrri", "ĥåçýджк", "DŽLjnj"]
System.print("Using 'Utf8' class methods:")
for (s in strs2) {
System.print(" original : %(s)")
System.print(" lower : %(Utf8.lower(s))")
System.print(" upper : %(Utf8.upper(s))")
System.print(" capitalize : %(Utf8.capitalize(s))")
System.print(" title : %(Utf8.title(s))")
System.print()
}</syntaxhighlight>
 
{{out}}
<pre>
Using 'Str' class methods:
ALPHABETA
original : alphaBETA
alphabeta
lower : alphabeta
upper : ALPHABETA
capitalize : AlphaBETA
title : AlphaBETA
swapCase : ALPHAbeta
 
original : ação
lower : ação
upper : AÇÃO
capitalize : Ação
title : Ação
swapCase : AÇÃO
 
original : o'hare O'HARE o’hare don't
lower : o'hare o'hare o’hare don't
upper : O'HARE O'HARE O’HARE DON'T
capitalize : O'hare O'HARE o’hare don't
title : O'hare O'HARE O’hare Don't
swapCase : O'HARE o'hare O’HARE DON'T
 
Using 'Utf8' class methods:
original : Stroßbùrri
lower : stroßbùrri
upper : STROẞBÙRRI
capitalize : Stroßbùrri
title : Stroßbùrri
 
original : ĥåçýджк
lower : ĥåçýджк
upper : ĤÅÇÝДЖК
capitalize : Ĥåçýджк
title : Ĥåçýджк
 
original : DŽLjnj
lower : džljnj
upper : DŽLJNJ
capitalize : DžLjnj
title : DžLjnj
</pre>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">string 0; \use zero-terminated string convention
include c:\cxpl\stdlib; \ToUpper, ToLower, and 'code' declarations
 
Line 3,202 ⟶ 4,019:
StrToLower(Str);
Text(0, Str); CrLf(0);
]</langsyntaxhighlight>
 
Output:
Line 3,213 ⟶ 4,030:
The English alphabet is a subset of the ASCII character set, and the upper and lower case letters are 32 bytes apart. Bit 5 "toggles" the case of any letter in this range. Assuming your string exists in RAM, these subroutines are all that is needed to switch the string from upper to lower case, and vice versa. The first two functions are destructive, meaning that you cannot recover the original string after using them. The <code>ToggleCase</code> function can be performed twice on the same string to get the original string back.
 
<langsyntaxhighlight lang="z80">ToUpperCase:
;INPUT:
;HL = BASE ADDRESS OF A NULL-TERMINATED STRING
Line 3,288 ⟶ 4,105:
pop de
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</langsyntaxhighlight>
 
{{out}}
Line 3,298 ⟶ 4,115:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">s:="alphaBETA";
s.toLower(); //--> "alphabeta"
s.toUpper(); //--> "ALPHABETA"</langsyntaxhighlight>
 
{{omit from|Openscad}}
Line 3,306 ⟶ 4,123:
 
=={{header|Zig}}==
<langsyntaxhighlight lang="zig">const std = @import("std");
 
pub fn main() !void {
Line 3,321 ⟶ 4,138:
 
// TODO use https://github.com/jecolon/zigstr
}</langsyntaxhighlight>
 
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
<lang Zoea>
program: uppercase
input: 'FOObar'
Line 3,332 ⟶ 4,149:
input: 'FOObar'
output: 'foobar'
</syntaxhighlight>
</lang>
{{Out}}
<pre>
162

edits