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

Find? Copy/Part?

 [1/15] from: carlos::lorenz::gmail::com at: 18-Jan-2005 11:13


Hi list, Suppose I have str: "aaa*aaa*aaa*aaa" Wich is the best way to get the position of second "*" at word str? -- *:-.,_,.-:*'``'*:-.,_,.-: Carlos Lorenz *:-.,_,.-:*'``'*:-.,_,.-:

 [2/15] from: volker:nitsch:gmai:l at: 18-Jan-2005 14:57


On Tue, 18 Jan 2005 11:13:57 -0200, Carlos Lorenz <carlos.lorenz-gmail.com> wrote:
> Hi list, > > Suppose I have str: "aaa*aaa*aaa*aaa" > > Wich is the best way to get the position of second "*" at word str? >
str: "aaa*aaa*aaa*aaa" probe find find/tail str "*" "*" ;or parse str[thru "*" to "*" p:] probe p ;or parse str[2 thru "*" p:] probe back p
> -- > *:-.,_,.-:*'``'*:-.,_,.-:
<<quoted lines omitted: 3>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler

 [3/15] from: ingo:2b1 at: 18-Jan-2005 23:38


Hi Carlos, here are the first 4 ideas I got
>> profiler/test [index? find next find str #"*" #"*"] 100000
== [0:00:00.213723]
>> profiler/test [parse str [2 [thru "*"] here: (pos: subtract index?
here 1)]] 100000 == [0:00:00.156568]
>> profiler/test [parse str [2 [thru #"*"] here: (pos: subtract index?
here 1)]] 100000 == [0:00:00.14909]
>> profiler/test [parse str [thru #"*" to #"*" here: (pos: index? here
)]] 100000 == [0:00:00.106628] As you'll clearly notice, parse is your friend ;0) I hope that helps Ingo Carlos Lorenz wrote:

 [4/15] from: carlos:lorenz::gmail at: 18-Jan-2005 15:05


Ingo, Thanks for you reply. I dir not think about parse though I can see you solve it using it. Parse yet has a not so confortable sintax to me so I try to avoid the use of it most part of the time. I'd like to have something just like I get in Visual Fox Pro. See below: * ------------------------------------------ a = "aaa*aaa*aaa*aaa" * gets the second ocurrence of "*" in the string from left to right pos = at( "*" , a , 2) * then asking VFP to grab a piece of the string up to the * second "*" in the string a ? left(a,pos) * gives the result aaa*aaa* * ------------------------------------------- Would it be very nice to have an AT-like native function in REBOL/Core, don't you think so? On Tue, 18 Jan 2005 23:38:43 +0900, Ingo Hohmann <[ingo--2b1--de]> wrote:
> Hi Carlos, > here are the first 4 ideas I got
<<quoted lines omitted: 23>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- *:-.,_,.-:*'``'*:-.,_,.-: Carlos Lorenz *:-.,_,.-:*'``'*:-.,_,.-:

 [5/15] from: gabriele:colellachiara at: 18-Jan-2005 18:18


Hi Carlos, On Tuesday, January 18, 2005, 6:05:40 PM, you wrote: CL> Would it be very nice to have an AT-like native function in CL> REBOL/Core, don't you think so? And what would it do, that FIND doesn't do already? Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/

 [6/15] from: carlos::lorenz::gmail::com at: 18-Jan-2005 16:14


Gabriele, The question is that I cannot figure out how to do it using find. Would you mind to give a help? On Tue, 18 Jan 2005 18:18:19 +0100, Gabriele Santilli <gabriele-colellachiara.com> wrote:
> Hi Carlos, > On Tuesday, January 18, 2005, 6:05:40 PM, you wrote:
<<quoted lines omitted: 9>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- *:-.,_,.-:*'``'*:-.,_,.-: Carlos Lorenz *:-.,_,.-:*'``'*:-.,_,.-:

 [7/15] from: andreas::bolka::gmx::net at: 18-Jan-2005 19:58


Tuesday, January 18, 2005, 6:05:40 PM, Carlos wrote:
> Parse yet has a not so confortable sintax to me so I try to avoid > the use of it most part of the time.
To me, the builtin 'parse is certainly one of the most powerful and most appealing features of REBOL :) So my personal suggestion would be: start getting comfortable with it ;) -- Best regards, Andreas

 [8/15] from: ammon:johnson:gm:ail at: 18-Jan-2005 11:57


Something like this? find-position: func [ series [series!] value [series!] count [integer!] /local cur-pos ][ cur-pos: copy series for i 1 count 1 [ cur-pos: find cur-pos value ] either none? cur-pos [ Print "The value does not exist in the series that many times." ][ return index? cur-pos ] ] I didn't test this, but it should at least give you an idea or two... Enjoy!! ~~Ammon ;~> On Tue, 18 Jan 2005 16:14:57 -0200, Carlos Lorenz <[carlos--lorenz--gmail--com]> wrote:
> Gabriele, > The question is that I cannot figure out how to do it using find.
<<quoted lines omitted: 29>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- Enjoy!! ~~~ Ammon ~~~ ~ Sui Generis ~ ~~~~ ;~> ~~~~

 [9/15] from: greggirwin:mindspring at: 18-Jan-2005 13:02

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


Hi Carlos, CL> Would it be very nice to have an AT-like native function in CL> REBOL/Core, don't you think so? Submit a wish request to RAMBO for a refinement on FIND. It could be very useful at times. I have to admit that I haven't found a deep need for it myself, because REBOL has different ways of dealing with things, but it could be a nice thing to make people more comfortable (and productive) when they move to REBOL from another language. I did the following to test the new PARSE feature that allows you to return from a parse action, so it will only work under the newest releases, but the idea could be adapted for the official releases. find-Nth: func [ "Returns the series at occurrence N of value or none." series [series!] value n [integer!] /local count pos ][ count: 0 parse series [ some [ to value pos: ( count: count + 1 if count = n [return pos] ) skip ] ] none ] test-Nth: func [ser val occ] [print mold find-Nth ser val occ] repeat i 6 [ test-Nth "aaa*bbb*ccc*ddd*eee*fff" #"*" i ] test-Nth "aaa bbb ccc ddd eee fff" #"*" 2 repeat i 5 [ test-Nth [aaa 0 bbb 1 ccc 0.0 ddd 2 eee 1.1 fff 3] integer! i ] repeat i 3 [ test-Nth [aaa 0 bbb 1 ccc 0.0 ddd 2 eee 1.1 fff 3] decimal! i ] repeat i 7 [ test-Nth [aaa 0 bbb 1 ccc 0.0 ddd 2 eee 1.1 fff 3] number! i ] test-Nth [aaa 0 bbb 1 ccc 0.0 ddd 2 eee 1.1 fff 3 x] number! 7 test-Nth [aaa 0 bbb 1 ccc 0.0 ddd 2 eee 1.1 fff 3 x] issue! 1 Then you can easily emulate what you want from Fox.
>> s: "aaa*bbb*ccc*ddd*eee*fff" >> left: func [series pos] [copy/part series pos] >> left s find-Nth s #"*" 2
== "aaa*bbb" Or even go a step further.
>> up-to-Nth: func [series value n] [left series find-Nth series value n] >> up-to-Nth s #"*" 2
== "aaa*bbb" -- Gregg

 [10/15] from: carlos:lorenz:gma:il at: 18-Jan-2005 18:25


Gregg, Thanks for your example and advice on the topic.

 [11/15] from: ptretter::charter::net at: 18-Jan-2005 15:14

Re: Find? Copy/Part?


str: "aaa*aaa*aaa*aaa" myfunc: func [string section /mod][ mod: copy str loop section [mod: find next mod "*"] return mod ] Now you can get to any section you want not just the second one.
>> myfunc str 2
== "*aaa*aaa"
>> myfunc str 3
== "*aaa"
>>
Paul Tretter

 [12/15] from: volker:nitsch::gmail at: 18-Jan-2005 23:56


On Tue, 18 Jan 2005 15:05:40 -0200, Carlos Lorenz <[carlos--lorenz--gmail--com]> wrote:
> Ingo, > Thanks for you reply.
<<quoted lines omitted: 12>>
> aaa*aaa* > * -------------------------------------------
Your main problem is, you gave 'parse no chance to be good in your question. ;) if you had given this spec immediate, its easier. because we can drop this ugly position-handling. str: "aaa*bbb*ccc*ddd" parse str[ copy start [ 2 thru "*" ] ] probe start ;== "aaa*bbb*" Or more verbose: parse str[ copy start ; copy stuff in 'start for the following expr. [ 2 thru "*" ; the "regular expression" telling what to include ] ]
> Would it be very nice to have an AT-like native function in > REBOL/Core, don't you think so? >
No :) -- -Volker Any problem in computer science can be solved with another layer of indirection. But that usually will create another problem. David Wheeler

 [13/15] from: pwawood::mango::net::my at: 19-Jan-2005 8:12


Hi Carlos Ingo's first example used find: Index? find next find str #"*" #"*" If you insert ( )s it helps to see what's going on (though it would slow Rebol down) Index? (find (next (find str #"*")) #"*") Working from the inner parentheses (brackets) outward : 1. Find str #"*" sets the index of str at the first * found 2. Next ( ) sets the index of str to the next character 3. Find (( )) #"*" sets the index of str at the next * found 4. index? ((( ))) returns the value of the index as an integer. Hope this explanation helps. Peter

 [14/15] from: tomc::darkwing::uoregon::edu at: 18-Jan-2005 22:25


Carlos you might also consider converting your delimited string into a block (yes... with parse) and using the items in the block (more rebolish) does seem like what you ultimatly want to do with your string anyway
>> str: "aaa*bbb*ccc*ddd"
== "aaa*bbb*ccc*ddd"
>> blk: parse/all str "*"
== ["aaa" "bbb" "ccc" "ddd"]
>> second blk
== "bbb"
>> skip blk 2
== ["ccc" "ddd"]
>> select blk "ccc"
== "ddd" etc ... all of rebols series slicers and dicers On Tue, 18 Jan 2005, Volker Nitsch wrote:

 [15/15] from: carlos::lorenz::gmail::com at: 19-Jan-2005 10:22


Volker, As Gregg said earlier there are many ways of doing the same thing with REBOL and for sure they are all very interesting as the one you showed us Thanks On Tue, 18 Jan 2005 14:57:45 +0100, Volker Nitsch <volker.nitsch-gmail.com> wrote:
> On Tue, 18 Jan 2005 11:13:57 -0200, Carlos Lorenz > <carlos.lorenz-gmail.com> wrote:
<<quoted lines omitted: 30>>
> To unsubscribe from the list, just send an email to rebol-request > at rebol.com with unsubscribe as the subject.
-- *:-.,_,.-:*'``'*:-.,_,.-: Carlos Lorenz *:-.,_,.-:*'``'*:-.,_,.-:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted