Split delimited string and remove escape sequences : <p>I need to split a comma separated string, which contents are sometimes between quotes. An example could be:</p>

<blockquote>
  <p>1,"TEST",22345,"18,95", Ab"cde</p>
</blockquote>

<p>The first problem here is to split the string only when the comma is not surrounded by quotes like "18,95". I've done that with a simple Regex. The next problem is to cut out the quotes, where they surround the content. For "TEST" and "18,95" the quotes should be removed.The quote in Ab"cde should be left untouched. Here is my code so far:</p>

<pre><code>List&lt;string&gt; results = Regex.Matches(this.Content, @"[\""](.+?)[\""]|[^,]+")
                            .Cast&lt;Match&gt;()
                            .Select(m =&gt; m.Value)
                            .Select(s =&gt; s.StartsWith("\"") &amp;&amp; s.EndsWith("\"") ? s.Remove(1,1).Remove(s.Length-1,1) : s)
                            .ToList();
</code></pre>

<p>For the second <code>Select</code> I get an <code>ArgumentOutOfRangeException</code> since the second <code>Remove</code> doesn't work with <code>s</code> anymore. I thought it should work, but somehow doesn't.</p>

<p>If there is a better way to do this I would be happy to learn about it.</p>
