My string contains the bytes (e.g 0x27), basically what I need to do is convert that string array which contains the byte data to a byte data type, so then I can encode it in UTF8, so it displays meaningful info.
1 string array contains:
0x37, 0x32, 0x2d, 0x38, 0x33, 0x39, 0x37, 0x32,0x2d, 0x30, 0x31
I need that converted to a byte array, is that possible?
My code is:
string strData;
string strRaw;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.InnerXml = Data;
XmlElement xmlDocElement = xmlDoc.DocumentElement;
strData = xmlDocElement.GetAttribute("datalabel").ToString();
strRaw = xmlDocElement.GetAttribute("rawdata").ToString();
string[] arrData = strData.Split(' ');
string[] arrRaw = strRaw.Split(' ');
Thanks for any help.
To say the ‘string contains the bytes’ could be interpreted in a few ways. You can extract a string into bytes in a number of ways. Converting a string directly into bytes based on UTF8 encoding:
There are of course similar methods for other encodings.
Ignore the above
Your comment changes the way the question reads quite a bit! If your strings are just hex (i.e. the bytes are not encoded into the string) just convert from hex to integers. Something like….