[REBOL] Re: Newbie Q: Search and delete from a Block
From: dockimbel:free at: 8-Oct-2002 22:21
Hi Chris,
Christopher Ross-Gill wrote:
> Hi,
>
> > join word-split "hellotherethisisanexample" "this"
> > == "hellothereisanexample"
>
> >> rejoin word-split "hellotherethisisanexample" "this"
> == "hellothereisanexample"
>
> I'm sure there's a more elegant way to do it than my effort below, or one
> that splits the string at all instances of the word...
>
> - Chris
>
> --
> REBOL []
>
> word-split: func [
> string [string!] word [string!] /local first second
> ][
> if not second: find string word [return reduce [string]]
> first: copy/part string second
> second: copy skip second length? word
> return reduce [first second]
> ]
I would do it like that :
word-split: func [text [string!] value [string!] /local fst snd][
parse text [to value s: (fst: copy/part txt s) value s: (snd: copy
s)]
reduce [fst snd]
]
or
word-split: func [text [string!] value [string!] /local pos][
reduce [copy/part text pos: find text value copy skip pos length?
value]
]
which would make my java-addicted friends say: "REBOL has a really bad
syntax" ! ;-)
-DocKimbel