Cut off LAST letter(s)?

Discuss news styles, css code, and other Coranto customizations in here...the possibilities are endless, so have at it!

Moderator: Spunkmeyer

Cut off LAST letter(s)?

Postby Darren » Sat Jun 04, 2005 4:45 am

I'm currently using this bit of PerlCode to take just the first letter of a variable (in this case, $Subject):

Code: Select all
$firstletter = lc $Subject;
$firstletter =~ s/[^A-Za-z0-9\-\.]+//g;
$firstletter = lc( substr($firstletter,0,1) );

My question is, is there such a helpful bit of code that will remove the last two characters from a variable? Data in my $Category variable can be of various lengths, but I want to create a variable that always removes the last two letters from whatever the value is.

Posts: 44
Joined: Sat Oct 30, 2004 9:20 pm

Postby kriko » Sat Jun 04, 2005 7:51 am

Here's some code that should do it:
Code: Select all
$cutvariable = substr($variable, 0, -2);
Kristjan aka. kriko
now a wireless expert
User avatar
Posts: 3328
Joined: Sat Feb 24, 2007 8:13 pm

Postby Darren » Wed Jul 13, 2005 2:55 am

Perfect. Thanks very much!
Posts: 44
Joined: Sat Oct 30, 2004 9:20 pm

Return to Customization

Who is online

Users browsing this forum: No registered users and 1 guest