Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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 (Vicar) 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 having an uproarious good time at the Monastery: (5)
As of 2015-07-06 00:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls