Solved

last 3 chars

Posted on 2000-02-17
3
162 Views
Last Modified: 2010-03-05
how do i assign a new variable to be the last three characters of a variable

ie if $old is "hello.txt"
then $new becomes "txt"

thanks
0
Comment
Question by:boofulls
3 Comments
 

Accepted Solution

by:
spreq earned 50 total points
ID: 2530734
1. get total character
2. simple mathematic to get location for the first of last three character
3. use substring

eg
$old = "hello.txt";
$long=length($old);   #total char
$FirstOfThree=$long-3;  #simple math
$new=substr($FirstOfThree,0,3); #get the last char



0
 

Author Comment

by:boofulls
ID: 2530779
even though there was an error in the last line....;)
0
 
LVL 84

Expert Comment

by:ozo
ID: 2533152
$new=substr($old,-3);  #unless what you really want are all characters after the last '.'
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now