LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to Word Array?

I know that there is a string to byte array function, but I need a string to word array. Not knowing much about variable types in labview, the way I would do this would be to multiply the 0, n, 2n... bytes by 256, and add them to the 1, n+1, 2n+1... bytes respecitively, storing the result in a new array of words.

Is there a more elegant method or a built in function for doing so?
0 Kudos
Message 1 of 7
(6,088 Views)
Also, I have another question (which popped up after closer inspection). The file format I'm using is:

Two byte binary number (space) Two byte binary number (space) ... etc.

So the above would not help.

So what I did was decimate the array into 3 arrays and ignored the 3rd and did what I described above.

Is there a better way of doing this, also?

-Dobbs
0 Kudos
Message 2 of 7
(6,087 Views)
If you've got a two-byte BINARY number, none of the above will work. 😞 I think you mean a two-byte integer number. Also, the string to byte array converts strings to an array of their raw ASCII byte values. I thought that's what you wanted, but if what you are talking about is a string like "12 34 56 78" and you want an array with elements {12, 34, 56, 78}, you'll have to do some more fiddling. You could use the "Spreadsheet String to Array" function with as the delimiter. Just remember to slap an =CR LF at the end of your string. Also, make a %d (or %x if your string is hex) as the format specifier. Wire up a 2D (!) array of U16 and then index the output to get your 1D array of words.

Dan Press
www.primetest.com
0 Kudos
Message 5 of 7
(6,087 Views)
Terribly sorry, I meant an integer composed of 16 bits in a maximally efficient manner.
That is in binary format, as opposed to ASCII format.

(The format such that you can represent 0 to 65535 with 2 bytes on the hard drive. I call it a binary number, but I suppose you were thinking something like the ASCII string "01"?)

-Dobbs

It all works, though, except for my other and much stranger problem:

http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=506500000008000000A1270000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
0 Kudos
Message 7 of 7
(6,087 Views)
I have built a library VI for turning a string containing hex data into an array of bytes. This may be the kind of thing you are looking for.

After reading your answer that contains further questions, I did a quick modification to skip every third character.

My routine uses a for loop and then gets one character based on the loop index times 3, gets the second character by adding one to that and then puts the characters together.

I hope this helps.

Rob
0 Kudos
Message 3 of 7
(6,087 Views)
I think what you are asking for is a string to word array function that gives you an array of U16 integers. If so, I've got your example VI right here. Judge its elegance. Do I get extra points for using a function in the "Advanced" palette?

Dan Press
www.primetest.com
Message 4 of 7
(6,087 Views)
Exquisite. Thanks, even better than mine (which has an ugly for loop in it)

Technically mine decimates the array into four pieces and ignores the last two, but close enough. 🙂

-Dobbs
0 Kudos
Message 6 of 7
(6,087 Views)