[EMAIL PROTECTED] wrote:
>s: [ 9 8 7 6 5 4 3 2 1 ]
>
>How do I create the string "9.8.7.6.5.4.3.2.1" from it?

A simple way, good for most purposes, but incorrect when the
elements contain spaces:

   new-s: replace/all form s " " "."

A faster way, and correct when the elements contain spaces:

   new-s: make string! 2 * length? s
   foreach x s [new-s: insert insert new-s x #"."]
   new-s: head clear back new-s

This is faster mostly because all of the calls are native. Adjust
the initial string length for element data type - overestimate if
you have to.

This method is faster yet:

   parse/all new-s: form s [any [to " " x: (change x #".")]]

but it clobbers 'x and has same trouble with spaces in the data as
the first example. Note that the [to " "] parse rule is faster than
a [to #" "] rule would be, for reasons unknown.

Which method you would use depends on circumstances. Usually the
first method will do just fine. I like parse though... :)

>I thought that reform would have a /sepchar refinement, but it didnt.

Interesting idea.

Brian Hawley

Reply via email to