title: C#: Insert strings to another string - performance issue
body: <p>I have a string, which is long, and a sorted dictionary of indexes and values. I should go over the elements in the dictionary and insert the value to the specified index in the string. I wrote the following code, which works fine, but very slow:</p>
  
  <pre><code>private string restoreText(string text){
    StringBuilder sb = new StringBuilder(text);
    foreach(KeyValuePair&lt;int, string&gt; pair in _tags){
      sb.Insert(pair.Key, pair.Value);
    }
    return sb.ToString();
  }
  </code></pre>
  
  <p>The dictionary might be very big and contain 500,000 elements. 
  I think that what makes this function slow is the Insert() method. For dictionary of 100,000 elements, it took almost 5 seconds.</p>
  
  <p>Is there a more efficient way to write this method?</p>
  
  <p>Thanks,</p>
  
  <p>Maya</p>