[FIND] [FoxPro] Re: Find? Copy/Part?
[1/11] 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/
[2/11] from: lmecir:mbox:vol:cz at: 19-Jan-2005 12:01
Gabriele Santilli napsal(a):
>Hi Gregg,
>On Tuesday, January 18, 2005, 9:02:32 PM, you wrote:
<<quoted lines omitted: 16>>
>GI> none
>GI> ]
....
> find-nth: func [
> "Returns the series at occurrence N of value or none."
<<quoted lines omitted: 10>>
> pos
> ]
....
another option:
find-nth: func [
"Returns the series at occurrence N of value or none."
series [series!]
value
n [integer!]
/local pos
] [
parse series [n [to value pos: value] to end]
pos
]
[3/11] from: gabriele:colellachiara at: 19-Jan-2005 12:23
Hi Ladislav,
On Wednesday, January 19, 2005, 12:01:26 PM, you wrote:
LM> another option:
LM> find-nth: func [
LM> "Returns the series at occurrence N of value or none."
LM> series [series!]
LM> value
LM> n [integer!]
LM> /local pos
LM> ] [
LM> parse series [n [to value pos: value] to end]
LM> pos
LM> ]
The problem here is:
>> 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
== "*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 7
== "*fff"
>> find-nth "aaa*bbb*ccc*ddd*eee*fff" "*" 8
== "*fff"
so you'd need to check PARSE's result and return NONE if it didn't
match.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[4/11] from: andreas:bolka:gmx at: 19-Jan-2005 12:30
Wednesday, January 19, 2005, 12:23:28 PM, Gabriele wrote:
> so you'd need to check PARSE's result and return NONE if it didn't
> match.
and so that this exercise is not left to the reader:
find-nth: func [
"Returns the series at occurrence N of value or none."
series [series!]
value
n [integer!]
/local pos
] [
either parse series [n [to value pos: value] to end] [pos] [none]
]
--
Best regards,
Andreas
[5/11] from: lmecir::mbox::vol::cz at: 19-Jan-2005 12:33
One correction to obtain NONE when not found:
find-nth: func [
"Returns the series at occurrence N of value or none."
series [series!]
value
n [integer!]
/local pos
] [
if parse series [n [to value pos: value] to end] [pos]
]
[6/11] from: lmecir:mbox:vol:cz at: 19-Jan-2005 14:08
Andreas Bolka napsal(a):
>Wednesday, January 19, 2005, 12:23:28 PM, Gabriele wrote:
>>so you'd need to check PARSE's result and return NONE if it didn't
<<quoted lines omitted: 11>>
> either parse series [n [to value pos: value] to end] [pos] [none]
> ]
I sent my correction
find-nth: func [
"Returns the series at occurrence N of value or none."
series [series!]
value
n [integer!]
/local pos
] [
if parse series [n [to value pos: value] to end] [pos]
]
immediately, but it didn't make it to the list yet :-(
[7/11] from: gabriele:colellachiara at: 19-Jan-2005 15:20
Hi Ladislav,
On Wednesday, January 19, 2005, 2:08:04 PM, you wrote:
LM> immediately, but it didn't make it to the list yet :-(
I got it a while after my message, but just before Andreas'.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[8/11] from: andreas::bolka::gmx::net at: 19-Jan-2005 15:25
Wednesday, January 19, 2005, 2:08:04 PM, Ladislav wrote:
> immediately, but it didn't make it to the list yet :-(
i received it 5 minutes after i sent my reply :)
--
Best regards,
Andreas
[9/11] from: sqlab:gmx at: 19-Jan-2005 15:56
Hello
Can someone tell me why I get different results for n = 0
with these two variants?
find-nth0: func [
"Returns the series after the Nth occurrence of value or none."
series [series!]
value
N [integer!]
/local pos
] [
parse series [n [thru value] pos: to end]
pos
]
find-nth1: func [
"Returns the series after the Nth occurrence of value or none."
series [series!]
value
N [integer!]
/local pos
] [
parse series [n thru value pos: to end]
pos
]
>> find-nth1 "0**3*4" "*" 0
== none
>> find-nth0 "0**3*4" "*" 0
== "0**3*4"
>>
Or with other questions;
why is zero times [..] true
and zero times .. false?
Other n's give the same result
>> find-nth1 "0**3*4" "*" 3
== "4"
>> find-nth0 "0**3*4" "*" 3
== "4"
AR
> Andreas Bolka napsal(a):
> >Wednesday, January 19, 2005, 12:23:28 PM, Gabriele wrote:
<<quoted lines omitted: 34>>
> To unsubscribe from the list, just send an email to rebol-request
> at rebol.com with unsubscribe as the subject.
--
GMX im TV ... Die Gedanken sind frei ... Schon gesehen?
Jetzt Spot online ansehen: http://www.gmx.net/de/go/tv-spot
[10/11] from: gabriele:colellachiara at: 19-Jan-2005 16:04
Hi Anton,
On Wednesday, January 19, 2005, 3:56:33 PM, you wrote:
AR> Can someone tell me why I get different results for n = 0
AR> with these two variants?
Hmm, it might be an implementation side effect.
But that leads us to:
find-nth: func [
"Returns the series at occurrence N of value or none."
series [series!]
value
n [integer!]
/local pos
] [
n: n - 1
parse series [
n [thru value] to value pos:
]
pos
]
Regards,
Gabriele.
--
Gabriele Santilli <g.santilli-tiscalinet.it> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[11/11] from: greggirwin::mindspring::com at: 19-Jan-2005 10:50
Wow!
I never cease to be amazed how much I learn from the people in this
community. I'm sure I've never used "n thru" with PARSE. How much
other stuff don't I know? :)
-- Gregg
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted