String case: Difference between revisions

Add Ecstasy example
No edit summary
(Add Ecstasy example)
 
(39 intermediate revisions by 20 users not shown)
Line 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}}
Line 646 ⟶ 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}}==
<syntaxhighlight lang="rebol">str: "alphaBETA"
Line 704 ⟶ 894:
 
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$</syntaxhighlight>
 
==={{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}}===
Line 720 ⟶ 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 760 ⟶ 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}}===
Line 767 ⟶ 1,016:
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="lb">
input$ ="alphaBETA"
Line 781 ⟶ 1,032:
upper$ = UCase(s$) ;uppercase
lower$ = LCase(s$) ;lowercase</syntaxhighlight>
 
==={{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}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="runbasic">a$ ="alphaBETA"
Line 791 ⟶ 1,052:
==={{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}}===
Line 821 ⟶ 1,126:
:sub(Str1,2,length(Str1)-2)→Str1
:Pause Str1</syntaxhighlight>
 
==={{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}}==
Line 867 ⟶ 1,194:
String input = scope .("alphaBETA");
input.ToUpper();
Console.WritelnWriteLine(input);
input.ToLower();
Console.WritelnWriteLine(input);
}
}
Line 885 ⟶ 1,212:
> ^
^ <</syntaxhighlight>
 
=={{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}}==
Line 1,143 ⟶ 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}}==
Line 1,156 ⟶ 1,504:
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}}==
Line 1,188 ⟶ 1,556:
<syntaxhighlight lang="e">["alphaBETA".toUpperCase(),
"alphaBETA".toLowerCase()]</syntaxhighlight>
 
=={{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}}==
Line 1,216 ⟶ 1,619:
OUTPUT (LowerCased);
OUTPUT (TitleCased);</syntaxhighlight>
 
=={{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:
<syntaxhighlight lang="elena">import system'culture;
Line 1,225 ⟶ 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));
Line 1,253 ⟶ 1,671:
String.capitalize("αΒ")
# => Αβ
String.upcase("ß")
# => SS
</syntaxhighlight>
 
Line 1,262 ⟶ 1,682:
lower = toLower s
upper = toUpper s</syntaxhighlight>
 
=={{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}}==
Line 1,482 ⟶ 1,941:
end program doit
</syntaxhighlight>
 
=={{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|Frink}}==
Line 1,515 ⟶ 1,960:
<pre>imbiss</pre>
 
=={{header|FutureBasicGAP}}==
<syntaxhighlight lang="futurebasicgap">window 1LowercaseString("alphaBETA");
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</syntaxhighlight>
 
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())
<syntaxhighlight 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</syntaxhighlight>
Output:
<pre>
ALPHABETA
alphabeta
to_camel_case: alphaBeta
to_pascal_case: AlphaBeta
to_snake_case: alpha_beta
</pre>
 
=={{header|GAP}}==
<syntaxhighlight lang="gap">LowercaseString("alphaBETA");
UppercaseString("alphaBETA");</syntaxhighlight>
 
=={{header|GML}}==
Line 1,594 ⟶ 2,035:
strings.Map(unicode.SimpleFold, s))
}</syntaxhighlight>
 
Output:
{{out}}
 
<pre>
string: alphaBETA len: 9 runes
Line 1,623 ⟶ 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>
 
Line 1,679 ⟶ 2,147:
 
=={{header|Java}}==
The ''String'' class offers the ''toUpperCase'' and ''toLowerCase'' methods.
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());
Line 1,700 ⟶ 2,179:
var uppercase = string.toUpperCase();
var lowercase = string.toLowerCase();</syntaxhighlight>
 
=={{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:
<syntaxhighlight lang="jq"># like ruby's downcase - only characters A to Z are affected
Line 1,709 ⟶ 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;</syntaxhighlight>
</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">"alphaBETA" | ascii_upcase
"alphaBETA" | ascii_upcase
#=> "ALPHABETA"
 
"alphaBETA" | ascii_downcase
#=> "alphabeta"</syntaxhighlight>
 
jq -n '"á" | test("Á";"i")' # case-insensitive search
#=> true
</syntaxhighlight>
 
=={{header|Jsish}}==
Line 1,742 ⟶ 2,243:
julia> lowercase("alphaBETA")
"alphabeta"</syntaxhighlight>
 
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}}
<syntaxhighlight 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"
Line 1,753 ⟶ 2,264:
"alphabeta"
</syntaxhighlight>
 
{{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}}==
Line 1,779 ⟶ 2,305:
{span {@ style="text-transform:uppercase"} alphaBETA } -> ALPHABETA
</syntaxhighlight>
 
=={{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}}==
Line 1,842 ⟶ 2,380:
=={{header|Lua}}==
<syntaxhighlight lang="lua">str = "alphaBETA"
 
print( string.upper(str) )
print( string.lowerupper(str) )</syntaxhighlight> -- 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}}==
Line 2,198 ⟶ 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}}==
Line 2,797 ⟶ 3,396:
see upper(aString) + nl
</syntaxhighlight>
 
=={{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}}==
Line 2,972 ⟶ 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}}==
Line 3,231 ⟶ 3,881:
Case_Lower_Block(#1, CP)</syntaxhighlight>
 
=={{header|VisualV Basic(Vlang)}}==
{{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|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,309 ⟶ 3,922:
=={{header|Wren}}==
{{libheader|Wren-str}}
The 'Str' class supports the following methods:
<syntaxhighlight 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))</syntaxhighlight>
# ''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>
 
162

edits