Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's one way of doing it:</p> <p>Build a sample string of seven words, with an embedded new-line in the middle of the string. There are three lines worth.</p> <pre><code>text = (["now is the\ntime for all good"] * 3).join(' ').gsub(' ', '|') puts text # &gt;&gt; now|is|the # &gt;&gt; time|for|all|good|now|is|the # &gt;&gt; time|for|all|good|now|is|the # &gt;&gt; time|for|all|good </code></pre> <p>Process like this:</p> <pre><code>lines = [] chunks = text.gsub("\n", '|').split('|') while (chunks.any?) lines &lt;&lt; chunks.slice!(0, 7).join(' ') end puts lines # &gt;&gt; now is the time for all good # &gt;&gt; now is the time for all good # &gt;&gt; now is the time for all good </code></pre> <p>So, that shows we can rebuild the rows.</p> <p>Pretending that the words are actually columns from the pipe-delimited file we can make the code do the real thing by taking out the <code>.join(' ')</code>:</p> <pre><code>while (chunks.any?) lines &lt;&lt; chunks.slice!(0, 7) end ap lines # &gt;&gt; [ # &gt;&gt; [0] [ # &gt;&gt; [0] "now", # &gt;&gt; [1] "is", # &gt;&gt; [2] "the", # &gt;&gt; [3] "time", # &gt;&gt; [4] "for", # &gt;&gt; [5] "all", # &gt;&gt; [6] "good" # &gt;&gt; ], # &gt;&gt; [1] [ # &gt;&gt; [0] "now", # &gt;&gt; [1] "is", # &gt;&gt; [2] "the", # &gt;&gt; [3] "time", # &gt;&gt; [4] "for", # &gt;&gt; [5] "all", # &gt;&gt; [6] "good" # &gt;&gt; ], # &gt;&gt; [2] [ # &gt;&gt; [0] "now", # &gt;&gt; [1] "is", # &gt;&gt; [2] "the", # &gt;&gt; [3] "time", # &gt;&gt; [4] "for", # &gt;&gt; [5] "all", # &gt;&gt; [6] "good" # &gt;&gt; ] # &gt;&gt; ] </code></pre>
 

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