Gossamer Forum
Home : General : Perl Programming :

Detection of First Letter Capital Letters & String Manipulation

Quote Reply
Detection of First Letter Capital Letters & String Manipulation
I need to Detect when the first letter of a particular word (only one word in string) is Capitalised.
Then I need to Duplicate this capital letter.
For eg "From" converted to "FF"
Any Ideas?
Thanks in advance
Quote Reply
Re: Detection of First Letter Capital Letters & String Manipulation In reply to
Sure, how about:

$input = 'From';
$input =~ s/^([A-Z]).*/$1$1/;
print $input;

will print 'FF'. Hope that helps,

Alex
Quote Reply
Re: Detection of First Letter Capital Letters & String Manipulation In reply to
Thanks Alex

Compliments on a great product (DBMan) and an outstanding support forum
Quote Reply
Re: Detection of First Letter Capital Letters & String Manipulation In reply to
Hi,
This is not about the same topic, but it is related a bit to the original question.

How can I make a string come out to be ALPHABET ONLY ( a,b,c,...x,y, and z ONLY) and return error message if it has ANY weird character : such as: $ & ` % ^ ...

Thanks you in advance!
Quote Reply
Re: Detection of First Letter Capital Letters & String Manipulation In reply to
Sure:

my $string = 'sometextwith$!@#chars';
if ($string !~ /^[A-Za-z]+$/) {
print "Uh Oh! Weird stuff!";
}

What that says is if the contents of $string don't match the letters A-Z or a-z, then print an error.

Hope that helps,

Alex