Gossamer Forum
Home : General : Perl Programming :

chop last letter/alphabet from a string

Quote Reply
chop last letter/alphabet from a string
Hi All,

I need code to chop last letter from a string if the last letter is alphabet "s"

so, I have $term = 'cars';
chop($term);
it returns car which is ok but if the term is say "manhattan" or something else that doesn't end in "s" I want the term as is.

Thanks
Quote Reply
Re: [socrates] chop last letter/alphabet from a string In reply to
Code:
$term = 'cars';
if ($term =~ /s$/) {
chop($term);
}

..should do the trick Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] chop last letter/alphabet from a string In reply to
just 4 fun Smile

Code:
$term = 'cars';
if ($term =~ /^(.*)s$/) {
$term = $1;
}

Regards

n || i || k || o

Last edited by:

el noe: Mar 31, 2011, 2:10 PM
Quote Reply
Re: [Andy] chop last letter/alphabet from a string In reply to
Thanks, guys.