title: Best way to parse Space Separated Text
body: <p>I have string like this</p>
  
  <pre><code> /c SomeText\MoreText "Some Text\More Text\Lol" SomeText
  </code></pre>
  
  <p>I want to tokenize it, however I can't just split on the spaces. I've come up with somewhat ugly parser that works, but I'm wondering if anyone has a more elegant design.</p>
  
  <p>This is in C# btw.</p>
  
  <p><strong>EDIT:</strong> My ugly version, while ugly, is O(N) and may actually be faster than using a RegEx.</p>
  
  <pre><code>private string[] tokenize(string input)
  {
      string[] tokens = input.Split(' ');
      List&lt;String&gt; output = new List&lt;String&gt;();
  
      for (int i = 0; i &lt; tokens.Length; i++)
      {
          if (tokens[i].StartsWith("\""))
          {
              string temp = tokens[i];
              int k = 0;
              for (k = i + 1; k &lt; tokens.Length; k++)
              {
                  if (tokens[k].EndsWith("\""))
                  {
                      temp += " " + tokens[k];
                      break;
                  }
                  else
                  {
                      temp += " " + tokens[k];
                  }
              }
              output.Add(temp);
              i = k + 1;
          }
          else
          {
              output.Add(tokens[i]);
          }
      }
  
      return output.ToArray();            
  }
  </code></pre>