PDA

View Full Version : checking the first character of a string



snowball
09-24-2002, 12:07 AM
Hi

Can anyone help please ......

I need to check to see if the first character of a string is an upper case or lower case letter.


if ($n32 XXXXXXXXXXXXXXXX ) {
$in{'filedirname'} = "titles/";
} else {
$in{'filedirname'} = "graphics/";
}


so if $n32's first letter is ABCDEFGHIJKLMNOPQRSTUVWXYZ then do the fist option .......

if $n32's first letter is abcdefghijklmnopqrstuvwxyz then do the second option .........

what should the first line (or several lines before this) be ........



I would appreciate any help ....

Thanks

Snow.

fivesidecube
09-24-2002, 09:47 AM
snowball,

Try
if( $n32 =~ /^[A-Z]/ )
{
print "Upper case\n";
}
else
{
print "Lower case\n";
}This attempts to bind the contents to the regular expression /^[A-Z]/ (the first character is in the set of upper case characters). If it can, the expression is true otherwise false.

snowball
09-24-2002, 10:25 AM
Thanks ........

That's exactly it.

I appreciate it.

snow.