Greetings dears,
I'm trying to get the string (Normal string human readable) value of a hex string.
I have created a string with a value, then was able to change it to a hex string after converting the string to an array of bytes.
But I'm unable now to go back to the normal string value from Hex.
I'm getting a wrong value at the end.
With the help of this C# post I have been able to write this code:
public static void main(Args _args)
{
//-- From UTF-8 String to Hex
System.Text.Encoding encodingUTF8;
encodingUTF8 = System.Text.Encoding::get_UTF8();
str text = "Hello World";
str hexString = System.BitConverter::ToString(encodingUTF8.GetBytes(text));
//-- From Hex to UTF-8 String:
hexString = strReplace(hexString, "-", "");
int NumberChars = strLen(hexString);
System.Byte[] bytes = new System.Byte[NumberChars/2]();
for (int i = 0; i < NumberChars; i = 2)
bytes.SetValue(System.Convert::ToByte(subStr(hexString,i, 2), 16), i/2);
str fromHexString = encodingUTF8.GetString(bytes);
//-- End Hex
info(fromHexString);
}
The original Text is "Hello World", but the end result is "H�V���v�&�"
What am I missing/doing wrong?
Isn't there a built-in method that will convert from Hex to Bytes Array, similar to C#'s System.Convert.FromHexString(String s) ?
Any advice is appreciated :)
Thanks in advance!