How to remove (?) While we are converting our byte content from unicode to ansi character
It would be helpful if you post the input string as well as the output.
Encoding.Convert () will output '?' when it tries to convert a character to a source that doesn't have a matching character in the target encoding.
The sequence at the beginning of your output looks suspiciously close to the byte order mark (BOM). ANSI encodings do not have them, so if your Unicode stream has a BOM at the beginning, you can try to disable it before passing data to the converter.
source to share
In this particular case, it looks like your input contains things that shouldn't be there (see Michael's answer ).
In general, when converting encodings, you can implement your own fallback encoding mechanism using theEncoderReplacementFallback
. You can easily force it to return empty for unsupported characters. Just supply Encoding
that uses your reserve when converting.
source to share