title: Split a NSString to multiple commandline arguments
body: <p>I am getting a commandline string in my application and I am trying to run the same as an NSTask. I can convert it as a C-String and run it using system.</p>
  
  <pre><code>system([commandlineStr cStringUsingEncoding:NSUTF8StringEncoding]);
  </code></pre>
  
  <p>But I prefer using NSTask instead. For running as NSTask, I need to split the string as command and an array of arguments. Splitting with <em>space</em> doesn't work since there could be arguments with space in between. Currently they are either escaped or quoted. For eg:</p>
  
  <pre><code>cp "~/File with spaces" ~/Folder\ with\ spaces
  </code></pre>
  
  <p>Is there a built in way to split the string to multiple arguments or write a custom parsing logic for the same.</p>