views:

360

answers:

2

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.

+5  A: 

System.Text.ASCIIEncoding.ASCII.GetString will return a string from the given byte array.

Rune Grimstad
+1  A: 

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.

gimel