LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert string with numbers into U8 with ascii

Solved!
Go to solution

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

 

 

0 Kudos
Message 1 of 6
(9,140 Views)
Solution
Accepted by OnlyOne

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.

 



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 2 of 6
(9,133 Views)

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).

 

byte.png 

 

Regards (EDIT: Coq Rouge was faster)

______________
Florian Abry
Inside Sales Engineer, NI Germany
0 Kudos
Message 3 of 6
(9,129 Views)

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. 

0 Kudos
Message 4 of 6
(9,125 Views)

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 ?



Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
Message 5 of 6
(9,111 Views)

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. 

Message 6 of 6
(9,109 Views)