Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: [FIND] [FoxPro] Re: Find? Copy/Part?

From: gabriele::colellachiara::com at: 19-Jan-2005 11:30

Hi Gregg, On Tuesday, January 18, 2005, 9:02:32 PM, you wrote: GI> find-Nth: func [ GI> "Returns the series at occurrence N of value or none." GI> series [series!] GI> value GI> n [integer!] GI> /local count pos GI> ][ GI> count: 0 GI> parse series [ GI> some [ GI> to value pos: ( GI> count: count + 1 GI> if count = n [return pos] GI> ) skip GI> ] GI> ] GI> none GI> ] find-nth: func [ "Returns the series at occurrence N of value or none." series [series!] value n [integer!] /local pos ] [ if n = 1 [return find series :value] n: n - 1 parse series [ n thru value to value pos: ] pos ]
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 1
== "*bbb*ccc*ddd*eee*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 2
== "*ccc*ddd*eee*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 3
== "*ddd*eee*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 4
== "*eee*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 5
== "*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 6
== none
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 7
== none (Though I hoped that the IF N = 1 was not needed... :) If the value is just a character, you can simplify things out: find-nth: func [ "Returns the series at occurrence N of value or none." series [any-string!] value [char!] n [integer!] /local pos ] [ parse series [ n thru value pos: (pos: back pos) ] pos ] Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/