private void WriteWithReplace(string value, char[] find, string[] replace) {
Debug.Assert(value != null);
Debug.Assert(find.Length == replace.Length);
int length = value.Length;
int pos = 0;
while(pos < length) {
int newPos = value.IndexOfAny(find, pos);
if (newPos == -1) {
break; // not found;
}
// output clean leading part of the string
while (pos < newPos) {
Write(value[pos]);
pos ++;
}
// output replacement
char badChar = value[pos];
int i;
for(i = find.Length - 1; 0 <= i; i --) {
if(find[i] == badChar) {
Write(replace[i]);
break;
}
}
Debug.Assert(0 <= i, "find char wasn't realy find");
pos ++;
}
// output rest of the string
if(pos == 0) {
Write(value);
}
else {
while(pos < length) {
Write(value[pos]);
pos ++;
}
}
}