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
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
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.