Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A warning up front: there are many different ways to achieve this in Rebol. So you'll probably get quite a few different suggestions.</p> <p><strong>For a start, let's stick to your original approach of using FIND.</strong></p> <p>When you use FIND with a series, what you get is a new view onto the underlying series data, positioned at a different offset from the start of the series data.</p> <p>Let's start with some example data:</p> <pre><code>&gt;&gt; line: copy "this is foo#and here comes a long bar" == "this is foo#and here comes a long bar" </code></pre> <p>Let's FIND the <code>#</code> character within that line, and refer to the result as POS:</p> <pre><code>&gt;&gt; pos: find line "#" == "#and here comes a long bar" </code></pre> <p>As you can see, this basically already gives you the second part (what you called REST2) of your split. You'll only have to skip past the delimiter itself (and then copy the resulting string, to make it independent from the original LINE string):</p> <pre><code>&gt;&gt; rest: copy next pos == "and here comes a long bar" </code></pre> <p>For extracting the initial part, you can use a nice feature of COPY/part. The documentation of the "/part" refinement (try <code>help copy</code>) says: "Limits to a given length <strong>or position</strong>" (emphasis mine). We already have that position handy as POS. So:</p> <pre><code>&gt;&gt; ref: copy/part line pos == "this is foo" </code></pre> <p>And there you go! The complete code:</p> <pre><code>pos: find line "#" ref: copy/part line pos rest: copy next pos </code></pre> <p><strong>For reference, here's a PARSE-based approach:</strong></p> <pre><code>parse line [copy ref to "#" skip copy rest to end] </code></pre> <p>I'll let this stand without further explanation. If you want to know more about PARSE, a good place to start is the venerable <a href="http://www.rebol.com/docs/core23/rebolcore-15.html" rel="nofollow">"Parsing" chapter in the REBOL/Core Users Guide</a> (originally written for REBOL 2.3, but the basics are still mostly the same in current REBOL 2 and 3 versions).</p> <p><em>One ancillary note at the end: instead of a single-item string <code>"#"</code> you could also use a character which is written as <code>#"#"</code> in Rebol.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload