Alternative to multiple String.Replaces

c#, replace, string

Solution

For an 'easy' alternative just use a StringBuilder....

StringBuilder sb = new StringBuilder("11223344");

string myString =
    sb
      .Replace("1", string.Empty)
      .Replace("2", string.Empty)
      .Replace("3", string.Empty)
      .ToString();

Problem

My code uses `String.Replace` several times in a row: ``` mystring = mystring.Replace("somestring", variable1); mystring = mystring.Replace("somestring2", variable2); mystring = mystring.Replace("somestring3", variable1); ``` I suspect there's a better and faster way to do it. What would you suggest?

Original source

Related problems