The solution by TheRealSteveJudge is correct in principle, but it doesn't really tell you
how to take your
args
string to build the
replacementDictionary
and worse it suffers from the iterative processing of the
replacementDictionary
values giving a substitution cascade which Richard MacCutchan pointed out.
If your replacements are all
single character to single character then the
replacementDictionary
should be:
Dictionary<char, char> replacementDictionary = new Dictionary<char, char>();
and then you can use LINQ to map through the
text
to generate the output:
string output = string.Join(string.Empty, text.Select(c => {
char rep;
return replacementDictionary.TryGetValue(c, out rep) ? rep : c;
}));
Now to populate the
replacementDictionary
from the
args
:
first you need to split
args
on the '/'
then for each of those strings, split again on the '=' into a "key" and "value"
set the key/value pairs into the
replacementDictionary
.
If this is upper/lowercase independent, then first insert the key/value pair with both values as uppercase then repeat with both of them as lowercase. (Use the
char.ToUpper(c)
or
char.ToUpperInvariant(c)
as apropriate, and likewise,
char.ToLower(c)
/
char.ToLowerInvariant(c)
)