I have this code work in desktop app, but it doesn't work in Windows 8 Store app, because System.Text does not have ASCIIEncoding
support anymore:
tagdata
is a byte array
.
ASCIIEncoding.ASCII.GetString(tagdata).Trim();
Should I use UT8Encoding? I just want to convert the byte array into ASCII
text.
Thank you.
For a start, I'd suggest using Encoding.ASCII
everywhere instead of ASCIIEncoding.ASCII
- the latter somewhat implies that the ASCII
property is a member of the ASCIIEncoding
class, which it's not.
If you know that your byte array is just ASCII text, then you can use Encoding.UTF8
freely, as every character present in ASCII is represented the same way in both UTF-8 and ASCII.
If you want to check the validity first, you just need to check that every byte in the array is less than 128
bool isAscii = tagData.All(b => b < 128);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With