Reputation: 837
Does anybody have sample code to convert from binary data to string in c#?
Upvotes: 4
Views: 5817
Reputation: 927
In modern versions of .NET
, we can simply use the .ToString()
override of BinaryData
for a UTF-8
decoding of the contained bytes.
string data = myBinaryData.ToString()
Upvotes: 0
Reputation: 3683
Sounds like you just need to decode the binary data. Therefore you need an encoding (like utf-8 or unicode).
Example:
var textFromBinary = System.Text.Encoding.UTF8.GetString(myBinaryData);
Upvotes: 3
Reputation: 115867
If your binary data is stored in byte
array and you want to convert it to Base64-encoding, you can use Convert.ToBase64String
method:
var base64String = Convert.ToBase64String(yourBinaryDataHere);
Upvotes: 1