title: Finding all positions of substring in a larger string in C#
body: <p>I have a large string I need to parse, and I need to find all the instances of <code>extract"(me,i-have lots. of]punctuation</code>, and store the index of each to a list. </p>
  
  <p>So say this piece of string was in the beginning and middle of the larger string, both of them would be found, and their indexes would be added to the <code>List</code>. and the <code>List</code> would contain <code>0</code> and the other index whatever it would be.</p>
  
  <p>I've been playing around, and the <code>string.IndexOf</code> does <em>almost</em> what I'm looking for, and I've written some code - but it's not working and I've been unable to figure out exactly what is wrong:</p>
  
  <pre><code>List&lt;int&gt; inst = new List&lt;int&gt;();
  int index = 0;
  while (index &lt; source.LastIndexOf("extract\"(me,i-have lots. of]punctuation", 0) + 39)
  {
      int src = source.IndexOf("extract\"(me,i-have lots. of]punctuation", index);
      inst.Add(src);
      index = src + 40;
  }
  </code></pre>
  
  <ul>
  <li><code>inst</code> = The list</li>
  <li><code>source</code> = The large string</li>
  </ul>
  
  <p>Any better ideas?</p>