Put a string into byte array

Put a string into byte array
The StringToByteArr() is a two line function that puts a string into a byte array, often needed in order to transfer a string via a network.
1. public static byte[] StringToByteArr(string str)
2. {
3.     System.Text.ASCIIEncoding encoding = new 
   System.Text.ASCIIEncoding();
4.     return encoding.GetBytes(str);
5. }

Leave a Reply

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

Back To Top