title: Replacing multiple characters in a string, the fastest way?
body: <p>I am importing some number of records with multiple <code>string</code> fields from an old db to a new db. It seems to be very slow and I suspect it's because I do this:</p>
  
  <pre><code>foreach (var oldObj in oldDB)
  {
      NewObject newObj = new NewObject();
      newObj.Name = oldObj.Name.Trim().Replace('^', 'Č').Replace('@', 'Ž').Replace('[', 'Š')
          .Replace(']', 'Ć').Replace('`', 'ž').Replace('}', 'ć')
          .Replace('~', 'č').Replace('{', 'š').Replace('\\', 'Đ');
      newObj.Surname = oldObj.Surname.Trim().Replace('^', 'Č').Replace('@', 'Ž').Replace('[', 'Š')
          .Replace(']', 'Ć').Replace('`', 'ž').Replace('}', 'ć')
          .Replace('~', 'č').Replace('{', 'š').Replace('\\', 'Đ');
      newObj.Address = oldObj.Address.Trim().Replace('^', 'Č').Replace('@', 'Ž').Replace('[', 'Š')
          .Replace(']', 'Ć').Replace('`', 'ž').Replace('}', 'ć')
          .Replace('~', 'č').Replace('{', 'š').Replace('\\', 'Đ');
      newObj.Note = oldObj.Note.Trim().Replace('^', 'Č').Replace('@', 'Ž').Replace('[', 'Š')
          .Replace(']', 'Ć').Replace('`', 'ž').Replace('}', 'ć')
          .Replace('~', 'č').Replace('{', 'š').Replace('\\', 'Đ');
      /*
      ... some processing ...
      */
  }
  </code></pre>
  
  <p>Now, I have read some posts and articles through the Net where I have seen many different thoughts about this. Some say it's better if I'd do regex with <code>MatchEvaluator</code>, some say it's the best to leave it as is.</p>
  
  <p>While it's possible that it'd be easier for me to just do a benchmark case for myself, I decided to ask a question here in case someone else has been wondering about the same question, or in case someone knows in advance.</p>
  
  <p>So what is the fastest way to do this in C#?</p>
  
  <p><em>EDIT</em></p>
  
  <p>I have posted the benchmark <a href="https://stackoverflow.com/questions/11899668/replacing-multiple-characters-in-a-string-the-fastest-way/11900932#11900932">here</a>. At the first sight it looks like Richard's way might be the fastest. However, his way, nor Marc's, would do anything because of the wrong Regex pattern. After correcting the pattern from</p>
  
  <pre><code>@"\^@\[\]`\}~\{\\" 
  </code></pre>
  
  <p>to </p>
  
  <pre><code>@"\^|@|\[|\]|`|\}|~|\{|\\" 
  </code></pre>
  
  <p>it appears as if the old way with chained .Replace() calls is the fastest after all</p>