String case: Difference between revisions

Add Ecstasy example
(Add Ecstasy example)
 
(9 intermediate revisions by 7 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 726 ⟶ 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 820 ⟶ 1,016:
 
==={{header|Liberty BASIC}}===
{{works with|Just BASIC}}
{{works with|Run BASIC}}
<syntaxhighlight lang="lb">
input$ ="alphaBETA"
Line 835 ⟶ 1,033:
lower$ = LCase(s$) ;lowercase</syntaxhighlight>
 
==={{header|QBASICQBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
Line 844 ⟶ 1,042:
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="runbasic">a$ ="alphaBETA"
Line 1,360 ⟶ 1,560:
EasyLang does not have string case functions. The functions provided below only work with ASCII.
<syntaxhighlight lang="easylang">
func$ toUpper s$ .
proc toUppercase string$ . result$ .
for ic$ =in 1strchars to len strings$
code = strcode substr stringc$ i 1
if code >= 97 and code <= 122
code -= 32
.
resultres$ &= strchar code
.
return res$
.
func$ toLower s$ .
proc toLowercase string$ . result$ .
for ic$ =in 1strchars to len strings$
code = strcode substr stringc$ i 1
if code >= 65 and code <= 90
code += 32
.
resultres$ &= strchar code
.
return res$
.
string$ = "alphaBETA"
print string$
callprint toUppercasetoUpper string$ result$
print resulttoLower string$
result$ = ""
call toLowercase string$ result$
print result$
</syntaxhighlight>
{{out}}
Line 1,420 ⟶ 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,429 ⟶ 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,468 ⟶ 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 3,145 ⟶ 3,398:
 
=={{header|RPL}}==
{{works with|HP|48}}
RPL has very limited string features. Any user must build her/his own basic library.
≪ 1 OVER SIZE '''FOR''' j
{{works with|Halcyon Calc|4.2.7}}
"" 1 3 PICK SIZE FORDUP j DUP SUB
'''IF''' DUP "a" < OVER j"z" DUP> OR SUB'''THEN''' NUMDROP
DUP'''ELSE''' 109.5NUM 32 - ABSCHR 13 ≥j SWAP DUP 32 -REPL IFTE'''END'''
CHR + '''NEXT'''
≫ ≫ '<span style="color:blue">→UPPER</span>' STO
NEXT
SWAP DROP
'→MAJ' STO
"" 1 3 PICKOVER SIZE '''FOR''' j
OVERDUP j DUP SUB NUM
'''IF''' DUP 77.5"A" -< ABSOVER 13"Z" ≥ SWAP DUP> 32OR +THEN IFTEDROP
'''ELSE''' NUM 32 + CHR j SWAP REPL '''END'''
CHR +
'''NEXT'''
≫ ≫ '<span style="color:blue">→LOWER</span>' STO
SWAP DROP
'→MIN' STO
 
"alphaBETA" →MAJ<span style="color:blue">→UPPER</span>
"alphaBETA" →MIN<span style="color:blue">→LOWER</span>
{{out}}
<pre>
Line 3,172 ⟶ 3,420:
1: "alphabeta"
</pre>
 
2: "ALPHABETA"
1: "alphabeta"
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">"alphaBETA".downcase # => "alphabeta"
Line 3,686 ⟶ 3,933:
 
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="ecmascriptwren">import "./str" for Str, Utf8
 
var strs = ["alphaBETA", "ação", "o'hare O'HARE o’hare don't"]
162

edits