I asked a question here which got answers, but changed the topic in another direction. So that's why I formulate the question newly. My old question: File encoding doesn't work
My new question: How can I check, if a character in a string is encodable with a particular encoding? I want to know which character is creating the problems in my original code. I tried it with an approach of an answer I got on my old question, but that just created an error message which doesn't seem to make sense.
The message was, that there was an "error at index 262" on a line of about 10 characters.
That's the code:
string[] Lines = reactor.GetMergedLines();
string fileName = "foo.bar";
try
{
Encoding encoding = Encoding.GetEncoding(28605, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback);
for (int i = 0; i < Lines.Length; i++)
{
File.WriteAllLines(fileName, Lines, encoding);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}