How can i convert for example byte[] b = new byte[1]; b[1]=255
to string ?
I need a string variable with the value "255" string text= "255";
and then store it in a text file?
Starting from bytes:
byte[] b = new byte[255];
string s = Encoding.UTF8.GetString(b);
File.WriteAllText("myFile.txt", s);
and if you start from string:
string x = "255";
byte[] y = Encoding.UTF8.GetBytes(x);
File.WriteAllBytes("myFile2.txt", y);
No need to convert to string. You can just use File.WriteAllBytes
File.WriteAllBytes(@"c:\folder\file.txt", byteArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With