Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old December 21st, 2000, 03:35 PM
meeh82 meeh82 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2000
Location: Riverside, CA
Posts: 63 meeh82 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
How do you take a characters off the end of a varible or specify the size of a variable to be a certain size.

Reply With Quote
  #2  
Old December 21st, 2000, 07:24 PM
mickalo's Avatar
mickalo mickalo is offline
Ole` Timer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Location: N.W. Iowa
Posts: 469 mickalo User rank is Private First Class (20 - 50 Reputation Level)mickalo User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 5 h 19 sec
Reputation Power: 8
Send a message via AIM to mickalo Send a message via MSN to mickalo
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

Reply With Quote
  #3  
Old December 21st, 2000, 09:41 PM
123finder.com 123finder.com is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Posts: 73 123finder.com User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Or chomp() could do the job

------------------
- Son
123finder.com - Free Domain Name Generator
ad-rotator.com - Free ad rotator system for small businesses/sites

Reply With Quote
  #4  
Old December 21st, 2000, 09:49 PM
Anonym0us Anonym0us is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2000
Posts: 0 Anonym0us User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<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!


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Trimming the end of a variable


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway