How do I transform an ascii byte vector into a string?
Question
Given a byte array (byte[]) is there any quick (as in short and aesthetic) way of transforming this into a string och character array? Assume that the bytes in the array is text represented in ascii.
I'm working in c# right now, and can't find any obvious methods to use. But I'm also interested in a general solution applicable to any modern programming language.
Solution
System.Text.ASCIIEncoding.ASCII.GetString will return a string from the given byte array.
OTHER TIPS
Important note: as noted here - Strings are Unicode, so you must specify an encoding on conversion.
System.Text.ASCIIEncoding
is one option, but make sure that the byte array contains only ASCII encoded characters.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow