Solved

last 3 chars

Posted on 2000-02-17
3
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl script to count sepecial characters in a file 7 148
Perl output collect 7 69
Having a problem with ActiveState Perl on 64-bit Windows 7 3 77
Using Perl to parse rows 7 101
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…

763 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