Page 2 of 2

Posted: Tue Jul 19, 2005 1:53 pm
by PB
> let's simply code it for now... :-)

Here's what I've been using for ages:

Code: Select all

Procedure FindStringLast(string$,match$,startpos)
  Repeat : a=FindString(string$,match$,startpos) : If a<>0 : startpos=a+1 : EndIf : Until a=0
  ProcedureReturn startpos-1
EndProcedure

Debug FindStringLast("123-456-789","-",1) ; Returns 8, because last dash is 8th character.

Posted: Tue Jul 19, 2005 2:49 pm
by GeoTrail
That works perfectly, thanks PB :)

Posted: Thu Jul 28, 2005 5:29 pm
by blueznl

Code: Select all

Procedure.l x_rfindstring(string.s,find.s)                          ; find string find.s in string.s starting from the right side
  Protected l.l , p.l
  ;
  ; *** find a string in another string, starting from the right
  ;
  l.l = Len(find.s)
  p.l = Len(string.s)
  If l > 0 And p > 0
    p = p + l
    Repeat
      p = p - 1
    Until p.l = 0 Or Mid(string,p,l) = find
  EndIf
  ProcedureReturn p
EndProcedure
i admit it's probably not the best way to do it :-)

i think this should be a standard purebasic command though, imho etc.

Posted: Thu Jul 28, 2005 11:11 pm
by GeoTrail
blueznl, yeah I can't dissagre there ;)