Forgive me if I seem competitive Joel, but I
couldn't resist. I think this would be faster,
featuring the insert tail instead of append
optimization (which I probably learned from you):

        >> string: "abcdefghijklmnopqrstuvwxyz"
        == "abcdefghijklmnopqrstuvwxyz"
        >> block: copy []
        == []
        >> while [not tail? string][
                insert tail block copy/part string 5
                string: skip string 5
        ]
        == ""
        >> block
        == ["abcde" "fghij" "klmno" "pqrst" "uvwxy" "z"]

Note it does modify the index of the string, however
you can set it back afterwards. (And it won't matter
if you make a function of it and pass the string in).

Anton.


> Hi, Richard,
> 
> COFFRE Richard FTO wrote:
> > 
> > Hi Rebol fellows,
> > 
> > Is there a tip to quickly split a very long string more than
> > 2000 characters into n characters sub strings and to create
> > a list with these subsets ?
> > For instance :
> > 
> ...
> > 
> > I want to split this string into substrings of 5 characters...
> > 
> 
> Here's a quick-and-dirty solution:
> 
>     >> longstring: "abcdefghijklmnopqrstuvwxyz"
>     == "abcdefghijklmnopqrstuvwxyz"
>     >> i: 1
>     == 1
>     >> stringblock: []
>     == []
>     >> while [i <= length? longstring] [
>     [    append stringblock copy/part at longstring i 5
>     [    i: i + 5
>     [    ]
>     == 31
>     >> stringblock
>     == ["abcde" "fghij" "klmno" "pqrst" "uvwxy" "z"]
>     >>
> 
> -jn-
> 
> -- 
> ; Joel Neely                             joeldotneelyatfedexdotcom

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to