Possible Duplicate:
Encode to single byte extended ascii values
In C#, I'm trying to replace substrings in a string with non-printing characters (characters with byte codes above 0xE0). I've seen many questions that are going the other way -- i.e. trying to remove non-printing characters from a string -- but not trying to insert non-printing characters. The code below (which doesn't work correctly) is where I am now:
string[] _symbol = {"Hello", "the", "man"};
string _source = "\"Hello, Hello,\" the man said.\n\"Hello,\" the woman replied.";
string _expect = "\"\xF3, \xF3,\" \xF2 \xF1 said.\n\"\xF3,\" \xF2 wo\xF1 replied.";
byte[] tblix = { 0xF3, 0x00 };
string _repl, _dest;
_repl = System.Text.Encoding.UTF8.GetString(tblix, 0, 1);
_dest = _source.Replace(_symbol[0], _repl);
tblix[0]--;
_repl = System.Text.Encoding.UTF8.GetString(tblix, 0, 1);
_dest = _dest.Replace(_symbol[1], _repl);
tblix[0]--;
_repl = System.Text.Encoding.UTF8.GetString(tblix, 0, 1);
_dest = _dest.Replace(_symbol[2], _repl);
bool check = (_dest == _expect);
File.WriteAllText("temp.dat", _dest);
I am expecting to produce a string in _dest that is equivalent to _expect; If I use ASCII encoding, the non-printing characters revert to '?'. UTF8 doesn't work correctly either. Moreover, I want the output to be written to the file as a sequence of single-byte characters, so converting everything to a multibyte encoding would eventually require coming back to a single-byte representation. Is there a convenient way to do what I'm trying to accomplish? Thanks in advance for any suggestions.