|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
|||
|
|||
|
How do you take a characters off the end of a varible or specify the size of a variable to be a certain size.
|
|
#2
|
||||
|
||||
|
Hope this helps:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre> # our variable string $var = "some_string"; # give the numerical length of the variable $length_a = (length($var); # set the substr value to hack off # the last character. $length_b = (length($var) - 1); # this strips the last character off # off the $var $trimdown = substr($var,0,$length_b); Now $trimdown is the $var with the last character removed. [/code] Cheers, Mickalo ------------------ Thunder Rain Internet Publishing Providing Personal/Business Internet Solutions that work! http://www.thunder-rain.com |
|
#3
|
|||
|
|||
|
Or chomp() could do the job
------------------ - Son 123finder.com - Free Domain Name Generator ad-rotator.com - Free ad rotator system for small businesses/sites |
|
#4
|
|||
|
|||
|
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by meeh82:
How do you take a characters off the end of a varible or specify the size of a variable to be a certain size.[/quote] For example, you have a variable named $me that contains "iamveryspecial," and you want to trim it down to, let's say 7 characters. You would do this: $me = substr $me, 0, 7; # $me is now "iamvery" If you would like to remove, let's say, the last 5 characters, you would approach it like this: $me = substr $me, 0, -5; # $me is now "iamverysp" Hope this helps! |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Trimming the end of a variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|