The target string is "A + A_RT + B*A+AA". I want to replace A with B and B with A. But I don't want to replace A_RT to B_RT or AA to BB. The expected result is "B + A_RT + A*B+AA". How can I do this in C#? Thanks.
Currently I use the following codes, but it will replace A_RT to B_RT...
IDictionary<string, string> map = new Dictionary<string, string>()
{
{"A","B"},
{"B","A"},
};
string str = "A + A_RT + B*A+AA";
var regex = new Regex(String.Join("|", map.Keys));
var newStr = regex.Replace(str, m => map[m.Value]);