Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: finding the last occurence of substring in string

by Ratazong (Monsignor)
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

Replies are listed 'Best First'.
Re^2: finding the last occurence of substring in string
by RichardK (Parson) 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?
[prathap keerthipati]: how to update perl in unix
[hippo]: yum update perl
[hippo]: Other package managers are available
LanX wouldn't update system Perl!
[Discipulus]: prathap keerthipati might be it is better to install an alternative Perl instead and do not touch the system one
[LanX]: see perlbrew for alternative Perl installations
[marto]: unless you know exactly what you're doing an often saner option is to simply build another Perl rather than replace the system one

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2017-03-23 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (285 votes). Check out past polls.