Skip to content

Instantly share code, notes, and snippets.

@hishaamn
Last active October 15, 2023 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hishaamn/96d7e29d7e8c52fe9f5c82fd73d4d95e to your computer and use it in GitHub Desktop.
Save hishaamn/96d7e29d7e8c52fe9f5c82fd73d4d95e to your computer and use it in GitHub Desktop.
Extension method to decode an array of bytes
public static class StringExtension
{
public static string ToReadableMessage(this string stringFromSql)
{
var byteList = new List<byte>();
string hexPart = stringFromSql.Substring(2);
for (int i = 0; i < hexPart.Length / 2; i++)
{
string hexNumber = hexPart.Substring(i * 2, 2);
byteList.Add((byte)Convert.ToInt32(hexNumber, 16));
}
byte[] original = byteList.ToArray();
return Encoding.UTF8.GetString(original);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment