Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: finding the last occurence of substring in string

by Ratazong (Prior)
on Jul 26, 2012 at 16:37 UTC ( #983870=note: print w/ replies, xml ) Need Help??


in reply to finding the last occurence of substring in string

Just for the sake of TIMTOWTDI (or fun, or for following Matthew 20:16), you may apply the following algorithm:

  • get the index of the reversed substring in the reversed string
  • calculate the position (lengthOfString minus index minus lengthOfSubstring)(with a possible off-by-one-correction)

Rata


Comment on Re: finding the last occurence of substring in string
Re^2: finding the last occurence of substring in string
by RichardK (Priest) on Jul 27, 2012 at 10:20 UTC

    if you want to get the reverse index why not just use rindex ? :)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983870]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-10-02 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (60 votes), past polls