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

[REBOL] forming a string from a block but inserting a separation character Re:

From: brian:hawley:bigfoot at: 28-Aug-2000 20:28

[princepawn--lycos--com] wrote:
>s: [ 9 8 7 6 5 4 3 2 1 ] > >How do I create the string "" 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