title: Replacing strings in a string array efficiently
body: <p>I have a string array full of guids.  I am trying to replace certain guids with different guids. My approach is below;</p>
  
  <pre><code>var newArray = this.to.Select(s =&gt; s.Replace("e77f75b7-2373-dc11-8f13-0019bb2ca0a0", "1fe8f3f6-fe17-e811-80d8-00155d5ce473")
      .Replace("fbd0c892-2373-dc11-8f13-0019bb2ca0a0", "1fe8f3f6-fe17-e811-80d8-00155d5ce473")
      .Replace("76cd4297-1e31-dc11-95d8-0019bb2ca0a0", "eb892fb0-fe17-e811-80d8-00155d5ce473")
      .Replace("cd42bb68-2073-dc11-8f13-0019bb2ca0a0", "dc6077e2-fe17-e811-80d8-00155d5ce473")
      .Replace("96b97150-cd45-e111-a3d5-00155d10010f", "1fe8f3f6-fe17-e811-80d8-00155d5ce473")
      ).ToArray();
  </code></pre>
  
  <p>I have a few fields I am doing this for and it is leading to an OutOfMemoryException.  Is it because the Replace() method is creating a new array every time?  Is there a more efficient way to do this with an array of strings? This method is running for tens of thousands of records and so I think this is the issue.  When I comment these lines out then i do not get the exception.</p>
  
  <p>EDIT:  The data in the 'to' variable is a short string in each case, but this is run for thousands of records.  So 'to' might look like this for one record;</p>
  
  <pre><code>"systemuser|76cd4297-1e31-dc11-95d8-0019bb2ca0a0;contact|96b97150-cd45-e111-a3d5-00155d10010f"
  </code></pre>
  
  <p>It might have any of the guids I want to replace in it, so even though it might only have one guid in for that record, I need to run the full set of replaces() just in case it has any of them in it.</p>
  
  <p>Any pointers would be great! Thanks.</p>