Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This following code will handle the case you provided, but will break for anything more complex. Also, since you did not specify how it should handle long-form tags with inner text or HTML, it treats all tags as short-form ones (Run the code to see what I mean).</p> <p>Works with this input:</p> <pre> Hellotoevryone&lt;img height=&quot;115&quot; width=&quot;150&quot; alt=&quot;&quot; src=&quot;/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg&quot; /&gt;Iamsogladtoseeall. Hellotoevryone&lt;img src=&quot;/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg&quot; /&gt;Iamsoglad&lt;img src=&quot;baz.jpeg&quot; /&gt;toseeall. Hello&lt;span class=&quot;foo&quot;&gt;toevryone&lt;/span&gt;Iamso&lt;em&gt;glad&lt;/em&gt;toseeallTheQuickBrown&lt;img src=&quot;bar.jpeg&quot; /&gt;FoxJumpsOverTheLazyDog. Hello&lt;span class=&quot;foo&quot;&gt;toevryone&lt;/span&gt;Iamso&lt;em&gt;glad&lt;/em&gt;toseeall. Loremipsumdolorsitamet,consecteturadipiscingelit.Nullamacnibhelit,quisvolutpatnunc.Donecultrices,ipsumquisaccumsanconvallis,tortortortorgravidaante,etsollicitudinipsumnequeeulorem. </pre> <p>Breaks with this input (note the incomplete tag):</p> <pre> Hellotoevryone&lt;img height=&quot;115&quot; width=&quot;150&quot; alt=&quot;&quot; src=&quot;/Content/Edt/image/b4976875-8dfb-444c-8b32-cc b47b2d81e0.jpg&quot; /Iamsogladtoseeall. </pre> <pre><code>using System; using System.Text.RegularExpressions; using System.IO; using System.Collections.Generic; public static class CustomSplit { public static void Main(String[] args) { if (args.Length &gt; 0 &amp;&amp; File.Exists(args[0])) { StreamReader sr = new StreamReader(args[0]); String[] lines = sr.ReadToEnd().Split(new String[]{Environment.NewLine}, StringSplitOptions.None); int counter = 0; foreach (String line in lines) { Console.WriteLine("########### Line {0} ###########", ++counter); Console.WriteLine(line); Console.WriteLine(line.EnsureWordLength(10)); } } } } public static class EnsureWordLengthExtension { public static String EnsureWordLength(this String target, int length) { List&lt;List&lt;Char&gt;&gt; words = new List&lt;List&lt;Char&gt;&gt;(); words.Add(new List&lt;Char&gt;()); for (int i = 0; i &lt; target.Length; i++) { words[words.Count - 1].Add(target[i]); if (target[i] == '&lt;') { do { i++; words[words.Count - 1].Add(target[i]); } while(target[i] != '&gt;'); } if ((new String(words[words.Count - 1].ToArray())).CountCharsWithoutTags() == length) { words.Add(new List&lt;Char&gt;()); } } String[] result = new String[words.Count]; for (int j = 0; j &lt; words.Count; j++) { result[j] = new String(words[j].ToArray()); } return String.Join(" ", result); } private static int CountCharsWithoutTags(this String target) { return Regex.Replace(target, "&lt;.*?&gt;", "").Length; } } </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