I just wondered what\'s the easiest way to replace a string characters that must be replaced subsequently.
For example:
var str = \"[Hello World]\";
How about:
char[] replacedChars = str.SelectMany(ch =>
(ch == '[' ? new char[] {'[', '[', ']'} :
(ch == ']' ? new char[] {'[', ']', ']'} :
new char[] {ch}))).ToArray();
string replaced = new string(replacedChars);
Note that this avoids the multiple loops issue but creates at least as many arrays as there are characters in the input string so it might not be optimal in terms of performance.