I want to convert a string with hex number to byte array, this string includes a tip information, but I don't want to add this tip to byte arry.
the detail information please see the picture. I hope someone can give me some instructions, thanks a lot.
Solved! Go to Solution.
You could do something like this (if you always have 4 bytes)
The constant wired to the default value is U8 representation.
Hope this helps.
You could provide more information, like do all of the tips start with a ' symbol?
Also you could add some example code.
Am I going to the right direction?
The number of bytes is not a constant. It depends on the message command. So I should filter the tip information.
Then you can read until it can't scan a hex code anymore.
To be on the safe side, you could also cut the string like suggested by Giedrius.
I don't think the solution from Giedrius will result in what you want since it will convert every single byte into its ASCII code. FF for instance will result in an array of x70,x70 instead of xFF.
The accepted solution provided by Giedrius.S is not correct, based on the picture shown in the first post. That solution will not eliminate the spaces before the tip, and the string to byte array will convert the individual characters of "0", "8", "space", "9", etc. to they byte values. The correct solution, based on the picture is shown below:
That solution will not eliminate the spaces before the tip, and the string to byte array will convert the individual characters of "0", "8", "space", "9", etc. to they byte values.
Must agree on both of these. I haven't processed the spaces and missed the formatting necessary before the converson to binary. The author should remark the solution.
your solution is absolutely correct , thanks a again.
Meanwhile, thanks to Dan and Giedrius.S, your solution gives me some ideas.