LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to convert a string to byte array

Solved!
Go to solution

Hello,

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.

 da.JPG

Message 1 of 8
(6,638 Views)

You could do something like this (if you always have 4 bytes)

Read-Hex.png

 

The constant wired to the default value is U8 representation.

Hope this helps.

 

0 Kudos
Message 2 of 8
(6,634 Views)

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?

 

String.png

---

While evaluating my code please have in mind that I am a LV novice. Therefore sometimes my code might violate some coding rules that I have to learn about myself. But how else could I do that... 🙂

Chart zoom with "Mouse Over" effect
Message 3 of 8
(6,627 Views)

Hello Dan,

The number of bytes is not a constant. It depends on the message command. So I should filter the tip information.

0 Kudos
Message 4 of 8
(6,626 Views)

Then you can read until it can't scan a hex code anymore.

See image.

 

Read-Hex2.png

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.

 

Message 5 of 8
(6,608 Views)
Solution
Accepted by topic author WGQ

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:

 

Message Edited by smercurio_fc on 02-10-2010 10:04 AM
Message 6 of 8
(6,574 Views)

smercurio_fc wrote:

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.

---

While evaluating my code please have in mind that I am a LV novice. Therefore sometimes my code might violate some coding rules that I have to learn about myself. But how else could I do that... 🙂

Chart zoom with "Mouse Over" effect
0 Kudos
Message 7 of 8
(6,566 Views)

Hello Smercurio_fc,

your solution is absolutely correct , thanks a again.

Meanwhile, thanks to Dan and Giedrius.S, your solution gives me some ideas.

 

WGQ

0 Kudos
Message 8 of 8
(6,534 Views)