Skip to content

String/Byte-Array conversion

In order to convert a string to a byte-Array, you need to use the GetBytes() method of the Encoding class.

To convert a string to a byte array:

byte[] fromString = Encoding.UTF8.GetBytes("Hello world!");

To convert a byte array to a string:

string fromBytes = Encoding.UTF8.GetString(byteArray);

(source)

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.