1

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.

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.