11-18-2011 07:39 AM
Hello,
i have a string with only numbers 0..9.
Now i want to convert this into an U8-array.
This works up to here but now the problem: How can i change each character into its ascii-value?
Example:
input: 123 (string)
output: x31, x32, x33 (U8-array)
Thanks for the help
Solved! Go to Solution.
11-18-2011 07:58 AM
This is very easy
String To Byte Array Function
Owning Palette: String/Array/Path Conversion Functions
Converts a string into an array of unsigned bytes. Each byte in the array has the ASCII value of the corresponding character in the string.
11-18-2011 08:04 AM - edited 11-18-2011 08:05 AM
Hello OnlyOne,
There is a function doing what you want called "String to Byte Array" under "Programming>String>Conversion". It returns the ASCII code of the string as U8 (49 for x31 for example).
Regards (EDIT: Coq Rouge was faster)
11-18-2011 08:06 AM
You are right. I know that String to byte array could do that but I don't know that it gives as ASCII. Perhaps, I am doing it like this but end up with some error.
11-18-2011 08:15 AM
I
@shjukheter wrote:
You are right. I know that String to byte array could do that but I don't know that it gives as ASCII. Perhaps, I am doing it like this but end up with some error.
Now I am somewhat lost. If you use the function we have pointed you to. You will get wat you want the string "123" will be converted to an array with 3 numbers. 49,50,51 or 0x31,0x32,0x33 in hex. Do you want an array with the numbers 1,2,3 ?
11-18-2011 08:16 AM
If you look at the output of the string to U8 you get 49, 50, 51 or 0x31, 0x32, 0x33.
The for loop will give you strings 1, 23, and 3 I believe (you string subset has some logical errors in it). Since you are using the string as a hex value, you'll get 0x01, 0x23, and 0x03.