String case: Difference between revisions

From Rosetta Code
Content added Content deleted
(Changed task description, modified all code examples to suit.)
Line 1: Line 1:
{{task}}
{{task}}

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


==[[Ada]]==
==[[Ada]]==
Line 18: Line 19:
[[Category:Forth]]
[[Category:Forth]]


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


==[[JavaScript]]==
==[[JavaScript]]==
[[Category:JavaScript]]
[[Category:JavaScript]]


alert( "lower case text".toUpperCase() );
alert( "alphaBETA".toUpperCase() );
alert( "alphaBETA".toLowerCase() );


Output:
Output:
ALPHABETA
LOWER CASE TEXT
alphabeta


==[[Perl]]==
==[[Perl]]==
Line 35: Line 38:
'''Interpreter:''' [[Perl]] v5.x
'''Interpreter:''' [[Perl]] v5.x


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



==[[Python]]==
==[[Python]]==
Line 41: Line 47:


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


==[[SQL]]==
==[[SQL]]==

Revision as of 14:43, 13 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            \ shows: alphaBETA
s count 2dup upper type \ shows: ALPHABETA
s count 2dup lower type \ shows: 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)