title: Split a string that has white spaces, unless they are enclosed within "quotes"?
body: <p>To make things simple:</p>
  
  <pre><code>string streamR = sr.ReadLine();  // sr.Readline results in:
                                   //                         one "two two"
  </code></pre>
  
  <p>I want to be able to save them as two different strings, remove all spaces EXCEPT for the spaces found between quotation marks. Therefore, what I need is:</p>
  
  <pre><code>string 1 = one
  string 2 = two two
  </code></pre>
  
  <p>So far what I have found that works is the following code, but it removes the spaces within the quotes.</p>
  
  <pre><code>//streamR.ReadLine only has two strings
    string[] splitter = streamR.Split(' ');
      str1 = splitter[0];
      // Only set str2 if the length is &gt;1
      str2 = splitter.Length &gt; 1 ? splitter[1] : string.Empty;
  </code></pre>
  
  <p>The output of this becomes</p>
  
  <pre><code>one
  two
  </code></pre>
  
  <p>I have looked into <a href="https://stackoverflow.com/questions/554013/regular-expression-to-split-on-spaces-unless-in-quotes">Regular Expression to split on spaces unless in quotes</a> however I can't seem to get regex to work/understand the code, especially how to split them so they are two different strings. All the codes there give me a compiling error (I am using <code>System.Text.RegularExpressions</code>)</p>