title: Elegant way to split string into 2 strings on word boundaries to minimize length difference
body: <p>I have a working solution right now, but it seems really ugly for something so (seemingly) simple.  </p>
  
  <p>I tried just breaking it when adding a word goes over the halfway mark, both splitting before and after adding the word, but depending on the length of the words it's either imbalanced towards the first or second line.  </p>
  
  <p>Sample inputs that I was initially having trouble with before the convoluted fix:</p>
  
  <p>Input <code>"Macaroni Cheese"</code> and  <code>"Cheese Macaroni"</code></p>
  
  <p>Should output <code>"Macaroni&lt;br/&gt; Cheese"</code> and <code>"Cheese&lt;br/&gt; Macaroni"</code> respectively.</p>
  
  <p>But simpler solutions either worked on the first but not the second, or the other way around.</p>
  
  <p>So here's what I have that works, but I'm wondering if there's a more elegant way to do this.</p>
  
  <pre><code>public string Get2LineDisplayText(string original)
  {
      string[] words = original.Split(new[] {' ', '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries);
  
      //Degenerate case with only 1 word
      if (words.Length &lt;= 1)
      {
          return original;
      }
  
      StringBuilder builder = new StringBuilder();
      builder.Append(words[0]); //Add first word without prepending space
      bool addedBr = false;
      foreach (string word in words.Skip(1))
      {
          if (builder.Length + word.Length &lt; original.Length / 2) //Word fits on the first line without passing halfway mark
          {
              builder.Append(' ' + word);
          }
          else if (!addedBr) //Adding word goes over half, need to see if it's more balanced on the 1st or 2nd line
          {
              int diffOnLine1 = Math.Abs((builder.Length + word.Length) - (original.Length - builder.Length - word.Length));
              int diffOnLine2 = Math.Abs((builder.Length) - (original.Length - builder.Length));
              if (diffOnLine1 &lt; diffOnLine2)
              {
                  builder.Append(' ' + word);
                  builder.Append("&lt;br/&gt;");
              }
              else
              {
                  builder.Append("&lt;br/&gt;");
                  builder.Append(' ' + word);
              }
              addedBr = true;
          }
          else //Past halfway and already added linebreak, just append
          {
              builder.Append(' ' + word);
          }
      }
  
      return builder.ToString();
  }
  </code></pre>
  
  <p>Sample input/output:</p>