Reputation: 17293
Say, when I convert a string into a byte array using single-byte encoding, some characters will be replaced with '?':
string strData="©";
byte[] bytesData = Encoding.ASCII.GetBytes(strData);
Is there any way to find out if a string will lose some of it's data if I convert it to ANSI?
PS. I'm not inquiring about benefits of Unicode encodings, such as UTF-8.
Upvotes: 3
Views: 489
Reputation: 109080
If you instantiate your own Encoder
you can specify an EncoderFallback
, one of the pre-defined such objects is EncoderFallback.ExceptionFallback
which will:
throws an exception when an input character cannot be encoded
Upvotes: 3
Reputation: 20240
How about?
Encoding.ASCII.GetString(Encoding.ASCII.GetBytes(strData)) == strData;
Upvotes: 6