<head>
 <body>
  <toc>
   <these>
    <get>
     <stripped>
      <h1 class="title">split_any / by</h1>
      <div id="mainSection">
       <table>
        <col style="width: 5%"/>
        <tr>
         <td>
          <b>Definition:</b>
         </td>
         <td>
          <a href="sequence.htm">sequence</a> res = split_any(<a href="sequence.htm">sequence</a> source, 
                                                              <a href="object.htm">object</a> delimiters=", \t|")
<!--
                                                              <a href="object.htm">object</a> delimiters={',',' ','\t','|'})
                                                            , 
                                                             <a href="integer.htm#bool">bool</a> no_empty=<a href="logicops.htm#tf">true</a>, 
                                                             <a href="integer.htm">integer</a> limit=0)
-->
          <br>
          <i>-- or --</i>
          <br>
          <a href="sequence.htm">sequence</a> res = split_by(<a href="sequence.htm">sequence</a> source,
                                                             <a href="integer.htm">integer</a> l)
         </td>
        </tr>
        <tr>
         <td>
          <b>Description:</b>
         </td>
         <td>
            The split_any() function splits a sequence on any of the specified delimiters into a number of sub-sequences.
          <br>
          <br>
            The split_by() function splits a sequence into chucks of at most length l each.
          <br>
          <br>
            Returns a sequence, of sub-sequences of source. In the case of split_any, all instances of any of the specified delimiters are removed.
         </td>
        </tr>
        <tr>
         <td>
          <a href="p2js.htm"><span class="pwap2js"><b>pwa/p2js:</b></span></a>
         </td>
         <td>
          Supported.
         </td>
        </tr>
        <tr>
         <td>
          <b>Comments:</b>
         </td>
         <td>
            These functions may be applied to a string or any sequence.
            <br>
            <br>
            Should delimiters be an atom or {atom} then split_any() behaves identically to <a href="split.htm">split</a>(), that is with 
            no_empty=true and no limit.
            <br>
            <br>
<!--
            If no_empty is <a href="logicops.htm#tf">true</a>, any zero-length sub-sequences are not added to the result sequence. <br>
            Use this when leading, trailing, and duplicated delimiters are not significant.
            <br>
            <br>
            If limit is greater than 0, it specifies the maximum number of sub-sequences that will be created, otherwise there is no limit.
            <br>
            <br>
            The use of <a href="procedures.htm#namedparams">named parameters</a> is advised when setting no_empty and/or limit.
DEV: post 0.8.3, update rc tasks (8 of them).
-->
            Prior to version 0.8.3, this routine had a confusing, unhelpfully defaulted, and incorrectly documented "no_empty" parameter, which
            always needed setting to <a href="logicops.htm#tf">true</a>, along with an equally dubious "limit" that also never found any use.<br>
<!--
            Prior to version 1.0.0, delimeters was ", \t|", but that is incompatible with <a href="p2js.htm">pwa/p2js</a>, and changing it
            to a dword-sequence does not affect the functionality on the desktop (however you simply cannot have tab characters in strings 
            in JavaScript, see <a href="notp2js.htm">Incompatibilities</a>).
-->
         </td>
        </tr>
        <tr>
         <td>
          <b>Examples:</b>
         </td>
         <td>
<!--eucode>
?split_any("(one,two,three)","(,)")
?split_by("onetwothree",3)
-- Output:
--      {"one","two","three"}
--      {"one","two","thr","ee"}

for i=1 to 10 do
    ?split_by(tagset(i),3)
end for
-- Output:
--      {{1}}
--      {{1,2}}
--      {{1,2,3}}
--      {{1,2,3},{4}}
--      {{1,2,3},{4,5}}
--      {{1,2,3},{4,5,6}}
--      {{1,2,3},{4,5,6},{7}}
--      {{1,2,3},{4,5,6},{7,8}}
--      {{1,2,3},{4,5,6},{7,8,9}}
--      {{1,2,3},{4,5,6},{7,8,9},{10}}
</eucode-->
<pre>
<font color="#000000">s</font><font color="#0000FF"> =</font><font color="#5E005E"> split_any</font><font color="#0000FF">(</font><font color="#008000">"{one,two,three}"</font><font color="#0000FF">,</font><font color="#008000">"{,}"</font><font color="#0000FF">)</font>
<font color="#000080"><i>-- Output:
--      {"one","two","three"}
</i></font>
<font color="#008080">for</font><font color="#000000"> i</font><font color="#0000FF">=</font><font color="#000000">1</font><font color="#008080"> to</font><font color="#000000"> 10</font><font color="#008080"> do</font>
<font color="#0000FF">    ?</font><font color="#5E005E">split_by</font><font color="#0000FF">(</font><font color="#5E005E">tagset</font><font color="#800000">(</font><font color="#000000">i</font><font color="#800000">)</font><font color="#0000FF">,</font><font color="#000000">3</font><font color="#0000FF">)</font>
<font color="#008080">end for</font>
<font color="#000080"><i>-- Output:
--      {{1}}
--      {{1,2}}
--      {{1,2,3}}
--      {{1,2,3},{4}}
--      {{1,2,3},{4,5}}
--      {{1,2,3},{4,5,6}}
--      {{1,2,3},{4,5,6},{7}}
--      {{1,2,3},{4,5,6},{7,8}}
--      {{1,2,3},{4,5,6},{7,8,9}}
--      {{1,2,3},{4,5,6},{7,8,9},{10}}</i></font>
</pre>
<!--
            <br>
            The use of a <a href="procedures.htm#namedparams">named parameter</a> for no_empty makes the intent much clearer.
-->
         </td>
        </tr>
        <tr>
         <td>
          <b>Implementation:</b>
         </td>
         <td>
            See builtins\psplit.e (an autoinclude) for details of the actual implementation.
         </td>
        </tr>
        <tr>
         <td>
          <b>See Also:</b>
         </td>
         <td>
          <a href="join.htm">join</a>,
          <a href="flatten.htm">flatten</a>,
          <a href="columnize.htm">columnize</a>,
          <a href="split.htm">split</a>,
          <a href="shorten.htm">shorten</a>
         </td>
        </tr>
       </table>
      </div>
     </stripped>
    </get>
   </these>
  </toc>
 </body>
</head>
