convert string to byte array code example

Example 1: c# string to byte array

// Convert a string to a C# byte[]
//change encoding depending on your data
string someText = "some data as text.";
byte[] bytes = Encoding.ASCII.GetBytes(author);

// Convert a byte array to a C# string    
string str = Encoding.ASCII.GetString(bytes);  
Console.WriteLine(str);

Example 2: String by byte array in java

String str = "Example String";
 byte[] b = str.getBytes();

Example 3: python convert string to byte array

a_string = "abc"
encoded_string = a_string. encode()
byte_array = bytearray(encoded_string)
print(byte_array)