取消
显示结果 
搜索替代 
您的意思是: 

How to convert string with numbers into U8 with ascii

已解决!
转到解答

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 项奖励
1 条消息(共 6 条)
10,662 次查看
解答
已被主题作者 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)
2 条消息(共 6 条)
10,655 次查看

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 项奖励
3 条消息(共 6 条)
10,651 次查看

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 项奖励
4 条消息(共 6 条)
10,647 次查看

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)
5 条消息(共 6 条)
10,633 次查看

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. 

6 条消息(共 6 条)
10,631 次查看