Last active
October 15, 2023 19:28
-
-
Save hishaamn/96d7e29d7e8c52fe9f5c82fd73d4d95e to your computer and use it in GitHub Desktop.
Extension method to decode an array of bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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