I m looking for the fastest way to replace multiple (~500) substrings of a big (~1mb) string. Whatever I have tried it seems that String.Replace is the fastest way of doing
It sounds like you are tokenising the string? I would look at producing a buffer and indexing your tokens. Or using a templating engine
As a naive example you could use code generation to make the following method
public string Produce(string tokenValue){
var builder = new StringBuilder();
builder.Append("A");
builder.Append(tokenValue);
builder.Append("D");
return builder.ToString();
}
If your running the iterations enough times, the time to build the template will pay for itself. You can then also call that method in parallel with no side effects. Also look at interning your strings