How to manipulate the cases of letters in a string?

P

Paul Lalli

Say, change "i LOVE this Game" into "I LOVE THIS GAME" or "i love this
game"

Jim has already given you the answer, so just some extra
information... You may not be aware of this, but you can get a listing
of ALL Perl functions, ordered by category, by typing this at your
command prompt:

perldoc perlfunc

If you do that, you will see, for example:
Functions for SCALARs or strings
"chomp", "chop", "chr", "crypt", "hex", "index", "lc",
"lcfirst", "length", "oct", "ord", "pack", "q/STRING/",
"qq/STRING/", "reverse", "rindex", "sprintf", "substr",
"tr///", "uc", "ucfirst", "y///"

Perhaps not the most helpful in this case, as it may not be intuitive
that "lc" stands for "lowercase", but it's still good to know in
general.

Paul Lalli
 
G

Greg Bacon

: Say, change "i LOVE this Game" into "I LOVE THIS GAME" or "i love this
: game"

$ cat try
#! /usr/bin/perl

$_ = "i LOVE this Game";

print "\U$_\n",
"\L$_\n";

$ ./try
I LOVE THIS GAME
i love this game

Hope this helps,
Greg
 
R

Reinhard Pagitsch

Petr said:
Your answer is short and to the subject, but not all perl programmers
use Linux. I can mention only that some of us are using ActiveState Perl
and we have not any perldoc.exe on our Windows PCs :)

We have perldoc.bat on our system in the \perl\bin directory.
And we have also the HTML documentation under \perl\html.
Simply open the index.html, in the left frame search for perlfunc, klick
it and search for upper.

Maybe will be better to write some "OS independent", e.g. "look at
function uc()".
I don't know what type of documentation is on Mac.

I think the same as on Win. or Unix: perldoc and/or the HTML documentation.

regards,
Reinhard

--
 
A

A. Sinan Unur

Your answer is short and to the subject, but not all perl programmers
use Linux. I can mention only that some of us are using ActiveState
Perl and we have not any perldoc.exe on our Windows PCs :)

C:\DOCUME~1\asu1\LOCALS~1\Temp> perldoc -f uc
uc EXPR
uc
Returns an uppercased version of EXPR. This is the internal
function implementing the "\U" escape in double-quoted strings.
Respects current LC_CTYPE locale if "use locale" in force. See
perllocale and perlunicode for more details about locale and
Unicode support. It does not attempt to do titlecase mapping on
initial letters. See "ucfirst" for that.

If EXPR is omitted, uses $_.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top