A blog post I saw recently (A .Net Unicode Puzzle) reminded me of a sample we’d written for the .Net Framework Samples. “Fallback Encoding Application Sample” demonstrates the Encoding/Decoding and Fallback classes, using the various APIs provided.
Since our inputs were more limited than other programs might be, we stretched to use some of the methods we wouldn’t have ordinarily chosen, but GetBytes/GetChars, Encoders, Decoders and Convert are all shown.
There’s also an example of an Encoder best fit fallback class, which decomposes a string to normalization form NFKD, and then tries each part to see if it can be encoded. This is similar to solving the puzzle posed by Chris Mullins with the additional aspect of limiting the output to the set of characters supported by the target encoding.