String case: Difference between revisions
Content deleted Content added
Added Ed |
|||
(51 intermediate revisions by 26 users not shown) | |||
Line 20:
{{trans|Python}}
<
print(s.uppercase())
print(s.lowercase())</
{{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').
<
USING UCASE,R15
MVC UC,PG
Line 48:
LC DS CL(L'PG)
YREGS
END UCASE</
{{out}}
<pre>
Line 58:
but now EBCDIC coding with alphabetic in 3 sequences, makes things a bit longer to create
translation tables.
<
USING UCASE,R15
MVC UC,PG
Line 88:
ORG
YREGS
END UCASE</
{{out}}
<pre>
Line 97:
=={{header|4D}}==
<
$uppercase:=Uppercase($string)
$lowercase:=Lowercase($string)</
=={{header|6502 Assembly}}==
<syntaxhighlight lang="text"> .lf case6502.lst
.cr 6502
.tf case6502.obj,ap1
Line 200:
.az -#13
;------------------------------------------------------
.en </
Output:
<pre>
Line 206:
ALPHA, BETA, GAMMA, {[(<123@_>)]}.
alpha, beta, gamma, {[(<123@_>)]}.</pre>
=={{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.
<syntaxhighlight lang="68000devpac">UpperCase:
;input: A0 = pointer to the string's base address.
;alters the string in-place.
MOVE.B (A0),D0 ;load a letter
BEQ .Terminated ;we've reached the null terminator.
CMP.B #'a',D0 ;compare to ascii code for a
BCS .overhead ;if less than a, keep looping.
CMP.B #'z',D0 ;compare to ascii code for z
BHI .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
BEQ .Terminated ;we've reached the null terminator.
CMP.B #'A',D0 ;compare to ascii code for A
BCS .overhead ;if less than A, keep looping.
CMP.B #'Z',D0 ;compare to ascii code for Z
BHI .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:
RTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ToggleCase:
MOVE.B (A0),D0 ;load a letter and inc the pointer to the next letter
BEQ .Terminated ;we've reached the null terminator.
MOVE.B D0,D1 ;copy the letter
AND.B #%11011111 ;convert the copy to upper case so we can check it.
CMP.B #'A',D1 ;compare to ascii code for A
BCS overhead ;if less than A, keep looping.
CMP.B #'Z',D1 ;compare to ascii code for Z
BHI overhead ;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</syntaxhighlight>
=={{header|8080 Assembly}}==
<
jmp demo
;;; Convert CP/M string under [HL] to upper case
Line 244 ⟶ 307:
mvi c,9
jmp 5
str: db 'alphaBETA',13,10,'$'</
{{out}}
Line 251 ⟶ 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}}
<
PROC UpperCase(CHAR ARRAY text,res)
Line 287 ⟶ 445:
PrintF("Upper-case string: ""%S""%E",upper)
PrintF("Lower-case string: ""%S""%E",lower)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/String_case.png Screenshot from Atari 8-bit computer]
Line 298 ⟶ 456:
=={{header|ActionScript}}==
<
var upper:String = string.toUpperCase();
var lower:String = string.toLowerCase();</
=={{header|Ada}}==
<
use Ada.Characters.Handling, Ada.Text_IO;
Line 311 ⟶ 469:
Put_Line (To_Upper (S));
Put_Line (To_Lower (S));
end Upper_Case_String;</
=={{header|ALGOL 68}}==
Line 318 ⟶ 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''.}}
<
# Demonstrate toupper and tolower for standard ALGOL 68
Line 348 ⟶ 506:
string to lower(t);
printf(($"lowercase: "gl$, t))
)</
Output:
<pre>
Line 356 ⟶ 514:
=={{header|ALGOL W}}==
<
% algol W doesn't have standard case conversion routines, this is one way %
% such facilities could be provided %
Line 397 ⟶ 555:
write( text( 0 // 40 ) );
end.</
{{out}}
<pre>
Line 405 ⟶ 563:
=={{header|Amazing Hopper}}==
<syntaxhighlight lang="amazing hopper">
#include <hopper.h>
Line 441 ⟶ 599:
{_X_} // put processed string into the stack...
back
</syntaxhighlight>
{{out}}
<pre>
Line 484 ⟶ 642:
{{works with|APL}}
In the following example, puntuation is not covered. It is substituted by '*'.
<
AlphLower←'abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ'
AlphUpper←'ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ*'
Line 494 ⟶ 652:
AlphLower[AlphUpper⍳'I'm using APL!']
i*m using apl*
</syntaxhighlight>
==={{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">
⎕C 'Πέτρος is using APL!'
πέτροσ is using apl!
1 ⎕C 'Πέτρος is using APL!'
ΠΈΤΡΟΣ IS USING APL!
</syntaxhighlight>
Note: The I-Beam operator with code 819 is now deprecated in favor of the system function <code>⎕C</code>.
Line 511 ⟶ 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.
<
-- TEST -----------------------------------------------------------------------
Line 571 ⟶ 729:
end script
end if
end mReturn</
{{Out}}
<
=={{header|Arbre}}==
<
uppercase('alphaBETA') + '\n' + lowercase('alphaBETA') + '\n' -> io</
Output:
<pre>
Line 583 ⟶ 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}}==
<
print ["uppercase :" upper str]
print ["lowercase :" lower str]
print ["capitalize :" capitalize str]</
{{out}}
Line 599 ⟶ 852:
=={{header|AutoHotkey}}==
<
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"</
=={{header|AutoIt}}==
<
$sUppercase = StringUpper($sString) ;"ALPHABETA"
$sLowercase = StringLower($sString) ;"alphabeta"</
=={{header|Avail}}==
<
Print: lowercase "alphaBETA";</
=={{header|AWK}}==
<
a = "alphaBETA";
print toupper(a), tolower(a)
}</
Capitalize:
<
a = "alphaBETA";
print toupper(substr(a, 1, 1)) tolower(substr(a, 2))
}</
=={{header|BASIC}}==
{{works with|QBasic}}
<
PRINT UCASE$(s$)
PRINT LCASE$(s$)</
==={{header|Applesoft BASIC}}===
<
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$</
==={{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}}
<
original$ = "alphaBETA"
Line 650 ⟶ 909:
PRINT "Lower case: " FN_lower(original$)
PRINT "Upper case: " FN_upper(original$)
PRINT "Title case: " FN_title(original$)</
Output:
<pre>Original: alphaBETA
Line 657 ⟶ 916:
Title case: AlphaBETA</pre>
==={{header|
{{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 671 ⟶ 936:
'''Code Example'''
<
15 rem rosetta code
20 s$="alphaBETA"
Line 684 ⟶ 949:
75 next i
80 print:print "Uppercase: ";up$
90 print "Lowercase: ";lo$</
{{output}}
Line 697 ⟶ 962:
ready.
█</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}}===
<
110 PRINT "Lower case: ";LCASE$(TX$)
120 PRINT "Upper case: ";UCASE$(TX$)</
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="lb">
input$ ="alphaBETA"
Line 712 ⟶ 1,026:
end
</syntaxhighlight>
==={{header|PureBasic}}===
<
upper$ = UCase(s$) ;uppercase
lower$ = LCase(s$) ;lowercase</
==={{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"
print a$ '=> alphaBETA
print upper$(a$) '=> ALPHABETA
print lower$(a$) '=> alphabeta</
==={{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}}
<
Dim s AS String = "alphaBETA"
Line 738 ⟶ 1,106:
' Change 's' to Lower Case.
s = s.ToLower()</
<
:"abcdefghijklmnopqrstuvwxyz"→Str0
:Input ">",Str1
Line 757 ⟶ 1,125:
:End
:sub(Str1,2,length(Str1)-2)→Str1
:Pause Str1</
==={{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}}==
<
// Check whether a character is an upper or lowercase letter
Line 785 ⟶ 1,175:
writef("Uppercase: %S*N", strtoupper(s))
writef("Lowercase: %S*N", strtolower(s))
$)</
{{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.
<
> :: "`"` \"{"\` * | > , v
> ^
^ <</
=={{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.
<
& out$str$(upp$!s \n low$!s)</
Output:
<pre>ALPHABETA
Line 809 ⟶ 1,234:
=={{header|Burlesque}}==
<
blsq ) "alphaBETA"^^zz\/ZZ
"ALPHABETA"
"alphabeta"
</syntaxhighlight>
=={{header|C}}==
The <tt>tolower</tt> and <tt>toupper</tt> functions are locale-aware.
<
standard C strings.
This does not work for multibyte character sets. */
Line 852 ⟶ 1,277:
printf("lowercase: %s\n", t);
return 0;
}</
=={{header|C sharp|C#}}==
<
class Program
{
Line 879 ⟶ 1,304:
Console.WriteLine("Converted: {0}", newStr);
}
}</
Title case is a little different:
<
=={{header|C++}}==
Line 891 ⟶ 1,316:
This method does the transform in-place. Alternate methods might return a new copy or use a stream manipulator.
<
#include <string>
#include <cctype>
Line 911 ⟶ 1,336:
str.begin(),
(int(*)(int)) std::tolower);
}</
Here is sample usage code:
<
#include <string>
Line 926 ⟶ 1,351:
cout << foo << endl;
return 0;
}</
=={{header|Clojure}}==
<
(println (.toUpperCase string))
(println (.toLowerCase string))</
=={{header|CMake}}==
<
message(STATUS "Uppercase: ${s}")
string(TOLOWER alphaBETA s)
message(STATUS "Lowercase: ${s}")</
<pre>-- Uppercase: ALPHABETA
Line 944 ⟶ 1,369:
=={{header|COBOL}}==
===Standard-compliant Methods===
<
PROGRAM-ID. string-case-85.
Line 973 ⟶ 1,398:
GOBACK
.</
===Compiler Extensions===
<
PROGRAM-ID. string-case-extensions.
Line 1,007 ⟶ 1,432:
GOBACK
.</
=={{header|ColdFusion}}==
converting a string literal
<
<cfset lower = LCase("alphaBETA")></
converting the value of a variable
<
<cfset upper = UCase(string)>
<cfset lower = LCase(string)></
=={{header|Common Lisp}}==
You can use the ''string-upcase'' function to perform upper casing:
<
"ALPHABETA"</
and you can do lower casing by using ''string-downcase'':
<
"alphabeta"</
=={{header|Component Pascal}}==
BlackBox Component Builder
<
MODULE AlphaBeta;
IMPORT StdLog,Strings;
Line 1,049 ⟶ 1,474:
END AlphaBeta.
</syntaxhighlight>
Execute: ^Q AlphaBeta.Do<br/>
Output:
Line 1,056 ⟶ 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}}==
<
import std.stdio, std.string;
Line 1,064 ⟶ 1,499:
s.toUpper.writeln;
s.toLower.writeln;
}</
{{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">
OPEN (1,O,'TT:') ;open video
Line 1,080 ⟶ 1,535:
UPCASE STR
DISPLAY (1,STR,10) ;ALPHABETA</
=={{header|Delphi}}[[Category:Object Pascal]]==
<
writeln(lowercase('alphaBETA'));</
=={{header|DWScript}}==
<
PrintLn(LowerCase('alphaBETA'));</
=={{header|Dyalect}}==
<
print("Lower case: ", str.Lower(), separator: "")
print("Upper case: ", str.Upper(), separator: "")
print("Capitalize: ", str.Capitalize(), separator: "")</
=={{header|E}}==
<
"alphaBETA".toLowerCase()]</
=={{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
<
(string-downcase "alphaBETA")
→ "alphabeta"
Line 1,115 ⟶ 1,605:
(string-randcase "alphaBETA")
→ "AlPHaBeTA"
</syntaxhighlight>
=={{header|ECL}}==
<
STRING MyBaseString := 'alphaBETA';
Line 1,128 ⟶ 1,618:
OUTPUT (UpperCased);
OUTPUT (LowerCased);
OUTPUT (TitleCased);</
=={{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|Ed}}==
Searching for any lowercase or uppercase character is possible with either [a-z] or [A-Z] (or [:lower:] or [:upper:]) but substitution is not possible on character classes, in this instance, because there is no "to lower" or "to upper" function[ality]. The literal problem may be solved, however. Take the input file '''in''':
<pre>
alphaBETA
alphaBETA
alphaBETA
</pre>
With the following script, saved as '''String_case.ed''':
<syntaxhighlight lang="ed">
1s/a/A/g
1s/l/L/
1s/p/P/
1s/h/H/
2s/B/b/
2s/E/e/
2s/T/t/
2s/A/a/
3s/a/A/
%p
Q
</syntaxhighlight>
... and the command line:
<pre>
ed -s in < String_case.ed
</pre>
{{out}}
<pre>
ALPHABETA
alphabeta
AlphaBETA
</pre>
... which illustrates changing line 1's alphaBETA to all uppercase, line 2's alphaBETA to all lower case, and line 3's alphaBETA to have only the initial letter uppercase.
=={{header|Elena}}==
ELENA
<
public program()
Line 1,138 ⟶ 1,688:
string s1 := "alphaBETA";
console.writeLine(s1.toLower(currentLocale));
console.writeLine(s1.toUpper(currentLocale));
console.readChar()
}</
=={{header|Elixir}}==
The String module provides the following functions:
<
String.downcase("alphaBETA")
# => alphabeta
Line 1,157 ⟶ 1,702:
String.capitalize("alphaBETA")
# => Alphabeta
</syntaxhighlight>
As with most String functions in Elixir, these are fully compatible with Unicode.
<
String.downcase("αΒ")
# => αβ
Line 1,166 ⟶ 1,711:
String.capitalize("αΒ")
# => Αβ
String.upcase("ß")
# => SS
</syntaxhighlight>
=={{header|Elm}}==
<
s = "alphaBETA"
lower = toLower s
upper = toUpper s</
=={{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}}==
<
string:to_lower("alphaBETA").</
=={{header|Excel}}==
Take 3 cells, say A1,B1 and C1. In B1 type :
<
=LOWER(A1)
</syntaxhighlight>
and in C1 :
<
=UPPER(A1)
</syntaxhighlight>
For the stated input in A1, the result will be :
<syntaxhighlight lang="text">
alphaBETA alphabeta ALPHABETA
</syntaxhighlight>
=={{header|F Sharp|F#}}==
<
let s = "alphaBETA"
let upper = s.ToUpper()
let lower = s.ToLower()
</syntaxhighlight>
=={{header|Factor}}==
<
"alphaBETA" >upper ! "ALPHABETA"
"alphaBETA" >title ! "Alphabeta"
"ß" >case-fold ! "ss"</
=={{header|Falcon}}==
<
printl("alphaBETA".upper())</
=={{header|Fantom}}==
<
fansh> a := "alphaBETA"
alphaBETA
Line 1,230 ⟶ 1,816:
fansh> "BETAalpha".decapitalize // make sure first letter is not capital
bETAalpha
</syntaxhighlight>
=={{header|Forth}}==
Line 1,258 ⟶ 1,844:
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
<
implicit none
Line 1,295 ⟶ 1,881:
end subroutine To_Lower
end program example</
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,301 ⟶ 1,887:
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: <
CHARACTER*(*) TEXT
INTEGER I,C
Line 1,308 ⟶ 1,894:
IF (C.GT.0) TEXT(I:I) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"(C:C)
END DO
END</
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 <
TEXT(I:I) = XLATUC(ICHAR(TEXT(I:I)))
END DO</
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,317 ⟶ 1,903:
Here a complete example, using functions, and as far as I can tell, will work also with EBCDIC:
<syntaxhighlight lang="fortran">
module uplow
implicit none
Line 1,394 ⟶ 1,980:
end program doit
</syntaxhighlight>
=={{header|Frink}}==
<
a = "alphaBETA"
println[lc[a]]
println[uc[a]]
</syntaxhighlight>
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:
<
Produces:
Line 1,425 ⟶ 1,997:
As the Unicode standard for casing states, "it is important to note that no casing operations on strings are reversible:"
<
<pre>imbiss</pre>
=={{header|
<syntaxhighlight lang="gap">LowercaseString("alphaBETA");
UppercaseString("alphaBETA");</syntaxhighlight>
=={{header|GDScript}}==
{{works with|Godot|4.0.2}}
<syntaxhighlight lang="gdscript">
extends MainLoop
func _process(_delta: float) -> bool:
var string: String = "alphaBETA"
print(string.to_upper())
print(string.to_lower())
# Note: These will also add/remove underscores.
print("to_camel_case: ", string.to_camel_case())
print("to_pascal_case: ", string.to_pascal_case())
print("to_snake_case: ", string.to_snake_case())
return true # Exit
</syntaxhighlight>
{{out}}
<pre>
ALPHABETA
alphabeta
to_camel_case: alphaBeta
to_pascal_case: AlphaBeta
to_snake_case: alpha_beta
</pre>
=={{header|GML}}==
<
{
x = 'alphaBETA';
Line 1,473 ⟶ 2,041:
show_message(y);
show_message(z);
}</
=={{header|Go}}==
Line 1,479 ⟶ 2,047:
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.
<
import (
Line 1,506 ⟶ 2,074:
fmt.Println("Swapping case: ", // DzLjNJ
strings.Map(unicode.SimpleFold, s))
}</
{{out}}
<pre>
string: alphaBETA len: 9 runes
Line 1,536 ⟶ 2,106:
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}}==
<
println str.toUpperCase()
println str.toLowerCase()</
Output:
Line 1,549 ⟶ 2,144:
=={{header|Haskell}}==
<
s = "alphaBETA"
lower = map toLower s
upper = map toUpper s</
=={{header|HicEst}}==
<
EDIT(Text=str, UpperCase=LEN(str))
EDIT(Text=str, LowerCase=LEN(str))
EDIT(Text=str, UpperCase=1) </
=={{header|Icon}} and {{header|Unicon}}==
<
write(map("alphaBETA"))
write(map("alphaBETA",&lcase,&ucase))
end</
=={{header|IDL}}==
Line 1,576 ⟶ 2,171:
=={{header|J}}==
Use standard utilities:
<
ALPHABETA
tolower 'alphaBETA'
alphabeta</
or alternative definitions:
<
lower=: {&((97+i.26) -&32@[} i.256)&.(a.&i.)</
For example:
<
ALPHABETA
lower 'alphaBETA'
alphabeta</
=={{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());
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 "ß"</
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}}==
<
alert( "alphaBETA".toLowerCase() );</
Output:
Line 1,610 ⟶ 2,216:
{{works with|NJS| 0.2.5}}
<
var uppercase = string.toUpperCase();
var lowercase = string.toLowerCase();</
=={{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:
<
def ascii_downcase:
explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;
Line 1,622 ⟶ 2,240:
# 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>
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"
"alphaBETA" | ascii_downcase
#=> "alphabeta"
jq -n '"á" | test("Á";"i")' # case-insensitive search
#=> true
</syntaxhighlight>
=={{header|Jsish}}==
<
;msg;
;msg.toUpperCase();
Line 1,638 ⟶ 2,266:
;msg.toTitle();
;msg.toLocaleUpperCase();
;msg.toLocaleLowerCase();</
{{out}}
Line 1,650 ⟶ 2,278:
=={{header|Julia}}==
<
"ALPHABETA"
julia> lowercase("alphaBETA")
"alphabeta"</
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"> 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>
{{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}}==
<
fun main(args: Array<String>) {
Line 1,676 ⟶ 2,329:
println(s.capitalize())
println(s.decapitalize())
}</
{{out}}
Line 1,688 ⟶ 2,341:
=={{header|Lambdatalk}}==
Lambdatalk can take benefit from CSS rules.
<
{span {@ style="text-transform:lowercase"} alphaBETA } -> alphabeta
{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}}==
<
'alphaBETA'->uppercase&
'alphaBETA'->lowercase&
Line 1,705 ⟶ 2,370:
local(tolower = 'alphaBETA')
#tolower->lowercase
#tolower</
=={{header|Lingo}}==
Lingo has no case conversion functions, but for ASCII strings they can e.g. be implemented like this:
<
-- Lower to upper case (ASCII only)
-- @param {string} str
Line 1,737 ⟶ 2,402:
end repeat
return str
end</
<
-- "ALPHABETA"
put toLower("alphaBETA")
-- "alphabeta"</
=={{header|LiveCode}}==
<
ALPHABETA alphabeta</
=={{header|Logo}}==
Line 1,754 ⟶ 2,419:
=={{header|Lua}}==
<
print( string.
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}}==
<
define(`downcase', `translit(`$*', `A-Z', `a-z')')
define(`x',`alphaBETA')
upcase(x)
downcase(x)</
=={{header|Maple}}==
<
StringTools:-UpperCase(str);
StringTools:-LowerCase(str);</
produces
<pre> alphabeta</pre>
Line 1,775 ⟶ 2,484:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
ToUpperCase[str]
ToLowerCase[str]</
{{out}}
<pre>ALPHABETA
Line 1,783 ⟶ 2,492:
=={{header|MATLAB}} / {{header|Octave}}==
<
ans =
Line 1,793 ⟶ 2,502:
ans =
alphabeta</
=={{header|Maxima}}==
<
sdowncase('alphaBETA');</
=={{header|MAXScript}}==
Requires MAX 2008
<
print (toUpper str)
print (toLower str)</
=={{header|Mercury}}==
Line 1,809 ⟶ 2,518:
only affect unaccented Latin characters.
<syntaxhighlight lang="text">:- module string_case.
:- interface.
Line 1,824 ⟶ 2,533:
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.</
=={{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).
<
if string a:
if (ASCII(a) >= ASCII(i)) and (ASCII(a) <= ASCII(f)):
Line 1,862 ⟶ 2,571:
endfor
?
enddef;</
<
message tolower("alphaBETA");
end</
=={{header|min}}==
{{works with|min|0.19.3}}
<
"alphaBETA" lowercase
"alphaBETA" capitalize</
=={{header|MiniScript}}==
<
print "Upper Case of " + mixedString + " is " + mixedString.upper
print "Lower Case of " + mixedString + " is " + mixedString.lower</
{{out}}
<pre>
Line 1,884 ⟶ 2,593:
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}}==
<
echo -ag $lower(alphaBETA)</
=={{header|Modula-3}}==
<
IMPORT IO, Text, ASCII;
Line 1,919 ⟶ 2,732:
IO.Put(Upper("alphaBETA\n"));
IO.Put(Lower("alphaBETA\n"));
END TextCase.</
Output:
<pre>
Line 1,927 ⟶ 2,740:
=={{header|MUMPS}}==
<syntaxhighlight lang="mumps">
STRCASE(S)
SET UP="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Line 1,935 ⟶ 2,748:
WRITE !,"Lower: "_$TRANSLATE(S,UP,LO)
QUIT
</syntaxhighlight>
Output:<pre>
USER>DO STRCASE^ROSETTA("alphaBETA")
Line 1,945 ⟶ 2,758:
=={{header|Nanoquery}}==
<
println upper(string)
println lower(string)</
=={{header|Nemerle}}==
<
using System.Globalization;
Line 1,965 ⟶ 2,778:
}
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref savelog symbols
Line 1,977 ⟶ 2,790:
say abc.lower
say abc.upper(1, 1) -- capitalize 1st character
</syntaxhighlight>
=={{header|NewLISP}}==
<syntaxhighlight lang="newlisp">
(upper-case "alphaBETA")
(lower-case "alphaBETA")
</syntaxhighlight>
=={{header|Nial}}==
<
=ALPHABETA
tolower 'alphaBETA'
=alphabeta</
=={{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.
<
var s: string = "alphaBETA_123"
Line 2,000 ⟶ 2,813:
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.</
{{out}}
Line 2,007 ⟶ 2,820:
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}}==
<
string := "alphaBETA";
string->ToUpper()->PrintLine();
string->ToLower()->PrintLine();
</syntaxhighlight>
=={{header|Objective-C}}==
{{works with|GNUstep}}
{{works with|Cocoa}}
<
NSLog(@"%@", @"alphaBETA".lowercaseString);
NSLog(@"%@", @"foO BAr".capitalizedString); // "Foo Bar"</
=={{header|OCaml}}==
<
let str = "alphaBETA" in
print_endline (String.uppercase_ascii str); (* ALPHABETA *)
Line 2,030 ⟶ 2,860:
print_endline (String.capitalize_ascii str); (* AlphaBETA *)
;;</
=={{header|Octave}}==
<
slc = tolower(s);
suc = toupper(s);
disp(slc);
disp(suc);</
=={{header|Oforth}}==
<
"alphaBETA" toLower</
=={{header|OpenEdge/Progress}}==
<
lc("alphaBETA")
</syntaxhighlight>
=={{header|Oz}}==
Convert to upper/lower-case:
<
Str = "alphaBETA"
in
{System.showInfo {Map Str Char.toUpper}}
{System.showInfo {Map Str Char.toLower}}</
Capitalize:
<
[StringX] = {Link ['x-oz://system/String.ozf']}
in
{System.showInfo {StringX.capitalize "alphaBETA"}} %% prints "AlphaBETA"</
=={{header|Pascal}}==
<
// Uppercase and Lowercase functions for a minimal standard Pascal
// where no library routines for these operations exist
Line 2,131 ⟶ 2,961:
Writeln('Lower case : ',lcase(ab));
END.
</syntaxhighlight>
Demonstration:
Line 2,141 ⟶ 2,971:
Lower case : alphabeta
</pre>
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
var s := 'exAmpLe sTrinG';
s.ToLower.Println;
s.ToUpper.Println;
</syntaxhighlight>
{{out}}
<pre>
example string
EXAMPLE STRING
</pre>
=={{header|Peloton}}==
Iterating through the peerset
<
[<@ SAYELTLST>...</@>] <@ SAYHLPELTLST>...</@><@ DEFKEYELTLST>__SuperMacro|...</@>
<@ SAY&&&LIT>alphaBETA</@>
</@></
Same code in padded-out, variable-length English dialect
<
[<# SAY ELEMENT LIST>...</#>] <# SAY HELP ELEMENT LIST>...</#><# DEFINE KEYWORD ELEMENT LIST>__SuperMacro|...</#>
<# SAY SUPERMACRO LITERAL>alphaBETA</#>
</#></
Output.
Line 2,177 ⟶ 3,022:
=={{header|Perl}}==
{{works with|Perl|5.x}}
<
print uc($string), "\n"; # => "ALPHABETA"
print lc($string), "\n"; # => "alphabeta"
Line 2,183 ⟶ 3,028:
print ucfirst($string), "\n"; # => "AlphaBETA"
print lcfirst("FOObar"), "\n"; # => "fOObar"</
Also works in Perl 4 if the '''my''' is removed.
Line 2,189 ⟶ 3,034:
=={{header|Phix}}==
{{libheader|Phix/basics}}
<!--<
<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>
<!--</
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}}==
<
echo strtoupper($str), "\n"; // ALPHABETA
echo strtolower($str), "\n"; // alphabeta
Line 2,204 ⟶ 3,049:
echo lcfirst("FOObar"), "\n"; // fOObar
echo ucwords("foO baR baZ"), "\n"; // FoO BaR BaZ
echo lcwords("FOo BAr BAz"), "\n"; // fOo bAr bAz</
=={{header|Picat}}==
<
S = "alphaBETA",
println(to_uppercase(S)),
println(to_lowercase(S)).</
{{out}}
Line 2,217 ⟶ 3,062:
=={{header|PicoLisp}}==
<
(prinl (uppc Str))
(prinl (lowc Str)) )</
=={{header|Pike}}==
Line 2,225 ⟶ 3,070:
output will differ from run to run.
<
string s2 = "foo bar gazonk";
Line 2,234 ⟶ 3,079:
String.sillycaps(s2),
String.Elite.elite_string(s2));
</syntaxhighlight>
{{Out}}
<pre>
Line 2,249 ⟶ 3,094:
if sent raw wide strings.
<
void main()
{
Line 2,256 ⟶ 3,101:
s, lower_case(s));
write( string_to_utf8(out) );
}</
{{Out}}
<pre>
Line 2,264 ⟶ 3,109:
=={{header|PL/I}}==
<
declare s character (20) varying initial ('alphaBETA');
put skip list (uppercase(s));
put skip list (lowercase(s));
</syntaxhighlight>
<
/* An alternative to the above, which might be used if some */
/* non-standard conversion is required, is shown for */
Line 2,277 ⟶ 3,122:
put skip list ( translate(s, 'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ') );
</syntaxhighlight>
=={{header|PL/SQL}}==
<
vc VARCHAR2(40) := 'alphaBETA';
ivc VARCHAR2(40);
Line 2,289 ⟶ 3,134:
lvc := LOWER(vc); -- 'alphabeta'
uvc := UPPER(vc); -- 'ALPHABETA'
end; </
=={{header|Plain English}}==
<
Start up.
Put "alphaBeta" into a string.
Line 2,302 ⟶ 3,147:
Write the string to the console.
Wait for the escape key.
Shut down.</
{{out}}
<pre>
Line 2,311 ⟶ 3,156:
=={{header|Pop11}}==
<
lowertoupper(str) =>
uppertolower(str) =></
=={{header|Potion}}==
<
low = ("")
str length times (i) :
Line 2,340 ⟶ 3,185:
lowercase("alphaBETA") print
uppercase("alphaBETA") print</
=={{header|Powerbuilder}}==
<
ls_string = 'alphaBETA'
ls_string = Upper(ls_string)
ls_string = Lower(ls_string)</
=={{header|PowerShell}}==
<
$string = 'alphaBETA'
$lower = $string.ToLower()
Line 2,356 ⟶ 3,201:
$lower, $upper, $title
</syntaxhighlight>
{{Out}}
<pre>
Line 2,365 ⟶ 3,210:
=={{header|Python}}==
<
print s.upper() # => "ALPHABETA"
print s.lower() # => "alphabeta"
Line 2,375 ⟶ 3,220:
import string
print string.capwords("fOo bAR") # => "Foo Bar"</
string.capwords() allows the user to define word separators, and by default behaves slightly differently than title().
<
print string.capwords("foo's bar") # => "Foo's Bar"</
=={{header|QB64}}==
<
s = "alphaBETA"
PRINT "The original string: " + s
PRINT ""
PRINT "Translated to lowercase: " + LCASE$(s)
PRINT "Translated to uppercase: " + UCASE$(s)</
'''Optimized version:'''
Line 2,398 ⟶ 3,243:
* PRINT does not need empty quotes to print a blank line.
* Semi-colons use less data than the concatenation (+) method.
<
PRINT "The original string: "; s$: PRINT
PRINT "Converted to lowercase: "; LCASE$(s$)
PRINT "Converted to uppercase: "; UCASE$(s$)</
=={{header|Quackery}}==
<
witheach [ upper join ] ] is upper$ ( $ --> $ )
Line 2,414 ⟶ 3,259:
$ "PaTrIcK, I dOn'T tHiNk WuMbO iS a ReAl wOrD."
dup lower$ echo$ cr
upper$ echo$ cr</
{{Out}}
Line 2,423 ⟶ 3,268:
=={{header|R}}==
<
toupper(str)
tolower(str)</
=={{header|Racket}}==
<
(define example "alphaBETA")
Line 2,436 ⟶ 3,281:
;"alphabeta"
(string-titlecase example)
;"Alphabeta"</
=={{header|Raku}}==
Line 2,442 ⟶ 3,287:
In Raku, case modification is implemented as builtin subroutine or method:
<syntaxhighlight lang="raku"
say uc $word; # all uppercase (subroutine call)
say $word.uc; # all uppercase (method call)
Line 2,450 ⟶ 3,295:
say $word.tclc; # first letter titlecase, rest lowercase
say $word.wordcase; # capitalize each word
</syntaxhighlight>
Output:
<pre>ALPHA BETA
Line 2,459 ⟶ 3,304:
=={{header|Raven}}==
<
'alhpaBETA' lower</
=={{header|REBOL}}==
<
print ["Uppercase:" uppercase original]
print ["Lowercase:" lowercase original]</
Output:
Line 2,474 ⟶ 3,319:
=={{header|Red}}==
<
>> uppercase str
== "ALPHABETA"
Line 2,480 ⟶ 3,325:
== "alphabeta"
>> uppercase/part str 5
== "ALPHAbeta"</
=={{header|Retro}}==
<
'alphaBETA s:to-lower s:put</
=={{header|REXX}}==
===with TRANSLATE BIF===
The following code will execute correctly in '''ASCII''' and '''EBCDIC.
<
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*/</
===with PARSE UPPER & PARSE LOWER statements===
The following code will execute correctly in '''ASCII''' and '''EBCDIC.
<
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.*/</
===with UPPER & LOWER BIFs===
The following code will execute correctly in '''ASCII''' and '''EBCDIC.
<
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).*/</
===with UPPER statement===
The following code will execute correctly in '''ASCII''' and '''EBCDIC.
<
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.*/</
===with capitalized words===
The following code will execute correctly in '''ASCII''' and '''EBCDIC.
<
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,539 ⟶ 3,384:
end /*j*/
return substr($, 2) /*return the capitalized words. */</
Some older REXXes don't have a '''changestr''' BIF, so one is included here ───► [[CHANGESTR.REX]]. <br>
Line 2,552 ⟶ 3,397:
===with case swap===
The following code will execute correctly in '''ASCII''' and '''EBCDIC.
<
abc = "abcdefghijklmnopqrstuvwxyz" /*define all the lowercase letters. */
abcU = translate(abc) /* " " " uppercase " */
Line 2,560 ⟶ 3,405:
say x
say y
/*stick a fork in it, we're all done. */</
'''output'''
<pre>
Line 2,568 ⟶ 3,413:
===version 2===
<
x='alphaBETA'; Say ' x='||x
Say 'three ways to uppercase'
Line 2,580 ⟶ 3,425:
l2=lower(x); Say ' l2='l2
parse lower var x l3; Say ' l3='l3
</syntaxhighlight>
:Note: Parse options upper and lower not available in every Rexx
:Builtin functions upper and lower not available in every Rexx
Line 2,586 ⟶ 3,431:
For German input (considering umlaute) these will uppercase them:
<
uppercase: /*courtesy Gerard Schildberger */
return translate(changestr("ß",translate(arg(1),'ÄÖÜ',"äöü"),'SS'))
Line 2,595 ⟶ 3,440:
a=changestr("ß",a,'SS') /* replace ß with SS */
return translate(a) /* translate lowercase letters */
</syntaxhighlight>
Translation to lowercase is not similarly possible because of 'SS'->'ß' or -> 'ss' ??
<br>
Line 2,601 ⟶ 3,446:
=={{header|Ring}}==
<
aString = "WELCOME TO THE ring programming language"
see lower(aString) + nl
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}}==
<
"alphaBETA".upcase # => "ALPHABETA"
"alphaBETA".swapcase # => "ALPHAbeta"
"alphaBETA".capitalize # => "Alphabeta"</
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}}
<
=={{header|Rust}}==
{{works with|Rust| 1.3}}
<
println!("{}", "jalapeño".to_uppercase()); // JALAPEÑO
println!("{}", "JALAPEÑO".to_lowercase()); // jalapeño
}</
=={{header|Scala}}==
<
println(s.toUpperCase) //-> ALPHABETA
println(s.toLowerCase) //-> alphabeta
println(s.capitalize) //-> AlphaBETA
println(s.reverse) //-> ATEBahpla</
=={{header|Scheme}}==
<
(list->string (map char-upcase (string->list s)))
(list->string (map char-downcase (string->list s)))</
Using SRFI-13:
<
> (define s "alphaBETA gammaDELTA")
> (string-upcase s) ;; turn all into upper case
Line 2,647 ⟶ 3,516:
> (string-titlecase s) ;; capitalise start of each word
"Alphabeta Gammadelta"
</syntaxhighlight>
=={{header|Sed}}==
Piping through sed in bash:
<
echo "alphaBETA" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'</
Other functions:
<
echo "alphaBETA" | sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/'</
GNU sed supports special sequences to change case:
<
# to uppercase
$ echo alphaBETA | sed 's/.*/\U&/'
Line 2,667 ⟶ 3,536:
$ echo alphaBETA | sed 's/.*/\L&/'
alphabeta
</syntaxhighlight>
=={{header|Seed7}}==
Line 2,674 ⟶ 3,543:
=={{header|SenseTalk}}==
<
set letters to "alphaBETA"
put lowercase of letters // alphabeta
Line 2,689 ⟶ 3,558:
put letters //ALPHAbeta
</syntaxhighlight>
=={{header|Sidef}}==
<
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</
=={{header|Simula}}==
<
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;</
=={{header|Slate}}==
<
'alphaBETA' toUppercase.</
=={{header|Smalltalk}}==
<
'ALPHAbeta' asLowercase "-> 'alphabeta' "</
{{works with|Smalltalk/X}}
{{works with|VisualWorks Smalltalk}}
<
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)
<
'ĥåçýджк' asUppercase "-> 'ĤÅÇÝДЖК'
'abcäöüáéíýıijńǵȅȇȉ' asUppercase -> 'ABCÄÖÜÁÉÍÝIIJŃǴȄȆȈ'</
=={{header|SNOBOL4}}==
Line 2,727 ⟶ 3,596:
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.
<
uc uc = replace(str,&lcase,&ucase) :(return)
uc_end
Line 2,752 ⟶ 3,621:
output = ucfirst(str)
output = swapc(str)
end</
An alternative way of constructing the above that groups related functions together in a denser display:
<
define('LC(STR)')
define('UCFIRST(STR)')
Line 2,773 ⟶ 3,642:
output = ucfirst(str)
output = swapc(str)
END</
Output:
Line 2,781 ⟶ 3,650:
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}}
<
set @s = 'alphaBETA'
print upper(@s)
print lower(@s)</
=={{header|SQL PL}}==
{{works with|Db2 LUW}}
With SQL only:
<
values upper('alphaBETA');
values lower('alphaBETA');
Line 2,798 ⟶ 3,694:
-- Within a SQL query.
select upper('alphaBETA') from sysibm.sysdummy1;
</syntaxhighlight>
Output:
<pre>
Line 2,836 ⟶ 3,732:
=={{header|Standard ML}}==
<
val strlwr = String.map Char.toLower;</
Test
Line 2,850 ⟶ 3,746:
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.
<
. di strupper(s)
ALPHABETA
. di strlower(s)
alphabeta</
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.
<
. scalar b=ustrupper(a)
. di b
ἘΝ ἈΡΧΗ͂Ι ἘΠΟΊΗΣΕΝ Ὁ ΘΕῸΣ ΤῸΝ ΟΥ̓ΡΑΝῸΝ ΚΑῚ ΤῊΝ ΓΗ͂Ν
. di ustrlower(b)
ἐν ἀρχῆι ἐποίησεν ὁ θεὸς τὸν οὐρανὸν καὶ τὴν γῆν</
=={{header|Swift}}==
<
println("alphaBETA".uppercaseString)
println("alphaBETA".lowercaseString)
println("foO BAr".capitalizedString)</
{{output}}
<pre>
Line 2,879 ⟶ 3,775:
=={{header|Tcl}}==
<
# three built-in case conversion commands
Line 2,908 ⟶ 3,804:
swapcase Père ;# ==> pÈRE
swapcase_en Père ;# ==> pèRE</
=={{header|Toka}}==
Line 2,926 ⟶ 3,822:
=={{header|Transd}}==
<
MainModule: {
Line 2,934 ⟶ 3,830:
(lout (tolower s)))
)
}</
{{out}}
<pre>
Line 2,942 ⟶ 3,838:
=={{header|TUSCRIPT}}==
<
$$ MODE TUSCRIPT,{}
string="alphaBETA"
Line 2,951 ⟶ 3,847:
PRINT uppercase1
PRINT uppercase2
</syntaxhighlight>
Output:
<pre>
Line 2,957 ⟶ 3,853:
ALPHABETA
ALPHABETA
</pre>
=={{header|Uiua}}==
{{works with|Uiua|0.11.1}}
<syntaxhighlight lang="uiua">
¯"alphaBETA" # swapcase
⌵"alphaBETA" # upper
¯⌵"alphaBETA" # lower
±"alphaBETA123" # case mask 1=upper, -1=lower, 0=neither
</syntaxhighlight>
{{out}}
<pre>
"ALPHAbeta"
"ALPHABETA"
"alphabeta"
[¯1 ¯1 ¯1 ¯1 ¯1 1 1 1 1 0 0 0]
</pre>
Line 2,963 ⟶ 3,875:
For System V tr:
<
echo alphaBETA | tr '[A-Z]' '[a-z]' # => alphabeta</
For [[BSD]] tr, [[GNU]] tr, or any [[POSIX]] system:
<
echo alphaBETA | tr A-Z a-z # => alphabeta</
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 2,975 ⟶ 3,887:
{{works with|bash}}
<
echo ${s^^} # => ALPHABETA
echo ${s,,} # => alphabeta
echo ${s^} # => AlphaBETA</
===Z Shell===
{{works with|zsh}}
<
echo ${s:u} # => ALPHABETA
echo ${s:l} # => alphabeta</
=={{header|Ursa}}==
<
out (upper "alphaBETA") endl console</
=={{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.
<
to_upper = * -:~& ~=`A-~p letters
Line 3,001 ⟶ 3,913:
#show+
examples = <to_upper 'alphaBETA',to_lower 'alphaBETA'></
output:
<pre>ALPHABETA
Line 3,007 ⟶ 3,919:
=={{header|Vala}}==
<
string s = "alphaBeta";
// stores ALPHABETA to string
Line 3,013 ⟶ 3,925:
// stores alphabeta to string
string s_lower = s.down();
</syntaxhighlight>
=={{header|VBA}}==
<
Dim s As String
s = "alphaBETA"
Line 3,022 ⟶ 3,934:
Debug.Print LCase(s)
Debug.Print WorksheetFunction.Proper(s)
End Function</
Output:
Line 3,030 ⟶ 3,942:
=={{header|VBScript}}==
<
MyWord = UCase("alphaBETA") ' Returns "ALPHABETA"
MyWord = LCase("alphaBETA") ' Returns "alphabeta"</
=={{header|Vedit macro language}}==
<
IT("alphaBETA")
Case_Upper_Block(#1, CP)
Case_Lower_Block(#1, CP)</
=={{header|
{{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,092 ⟶ 3,967:
show('DŽLjnj')
show("o'hare O'HARE o’hare don't")
}</
Output:
<pre>
Line 3,118 ⟶ 3,993:
=={{header|Wren}}==
{{libheader|Wren-str}}
The 'Str' class supports the following methods:
# ''lower'' - converts all letters to lower case
# ''upper'' - converts all letters to upper case
# ''capitalize'' - converts only the first letter to upper case
# ''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:
original : 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}}==
<
include c:\cxpl\stdlib; \ToUpper, ToLower, and 'code' declarations
Line 3,148 ⟶ 4,090:
StrToLower(Str);
Text(0, Str); CrLf(0);
]</
Output:
Line 3,159 ⟶ 4,101:
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.
<
;INPUT:
;HL = BASE ADDRESS OF A NULL-TERMINATED STRING
Line 3,234 ⟶ 4,176:
pop de
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</
{{out}}
Line 3,244 ⟶ 4,186:
=={{header|zkl}}==
<
s.toLower(); //--> "alphabeta"
s.toUpper(); //--> "ALPHABETA"</
{{omit from|Openscad}}
Line 3,252 ⟶ 4,194:
=={{header|Zig}}==
<
pub fn main() !void {
Line 3,266 ⟶ 4,208:
try stdout_wr.print("upper: {s}\n", .{upper});
// TODO use https://
}</
=={{header|Zoea}}==
<syntaxhighlight lang="zoea">
program: uppercase
input: 'FOObar'
Line 3,278 ⟶ 4,220:
input: 'FOObar'
output: 'foobar'
</syntaxhighlight>
{{Out}}
<pre>
|