String case: Difference between revisions

From Rosetta Code
Content added Content deleted
Line 20: Line 20:


create s ," alphaBETA"
create s ," alphaBETA"
s count type \ shows: alphaBETA
s count type
s count 2dup upper type \ shows: ALPHABETA
s count 2dup upper type
s count 2dup lower type \ shows: alphabeta
s count 2dup lower type

Output:

alphaBETA
ALPHABETA
alphabeta


==[[JavaScript]]==
==[[JavaScript]]==

Revision as of 17:01, 14 February 2007

Task
String case
You are encouraged to solve this task according to the task description, using any language you may know.

Take the string "alphaBETA", and demonstrate how to convert it to UPPER-CASE and lower-case.

Ada

with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Text_Io; use Ada.Text_Io;

procedure Upper_Case_String is
   S : String := "alphaBETA";
begin
   Put_Line(To_Upper(S));
   Put_Line(To_Lower(S));
end Upper_Case_String;

Forth

create s ," alphaBETA"
s count type
s count 2dup upper type
s count 2dup lower type

Output:

alphaBETA
ALPHABETA
alphabeta

JavaScript

alert( "alphaBETA".toUpperCase() );
alert( "alphaBETA".toLowerCase() );

Output:

ALPHABETA
alphabeta

Perl

Interpreter: Perl v5.x

my $string = "alphaBETA";
my $uppercase = uc($string);
my $lowercase = lc($string);


Python

s = "alphaBETA"
print s.upper()
print s.lower()

SQL

--tested in Microsoft SQL 2005
declare @s varchar(10)
set @s = 'alphaBETA'
print upper(@s)
print lower(@s)


Tcl

set string alphaBETA
string toupper $string
# ==> ALPHABETA
string tolower $string
#==>  alphabeta