LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

string to array

I've got a string indicator full of HEX data that I'd like to put into an array by twos. Sounds easy enough. Problem is, I want the data loaded into the array two characters at a time with no fluff - no tabs (such as converting to a spreadsheet string). Here's what I want:

String = A2FF0CFAB301FFA .........and so on for 2048 characters.
Array = (1)A2 (2)FF (3)F0 (4)CF (5)AB (6)30 (7)1F (8)FA  ...........and so on for 1024 indexes.

I've tried some tricks with the Quotient & Remainder function in a FOR loop, but so far to no avail. The attached picture shows what I've done, but when the Case goes True, I have to load the next Index with something, which is what I want to avoid.

In basic, I'd just use For i = 0 to 2048 STEP 2 and load the array that way. Any ideas?



Richard






0 Kudos
Message 1 of 11
(4,281 Views)

Hi Richard,

Tricky problem...I think the String to Byte Array and Byte Array to String functions will help you.  I also used the Split 1D Array function in a loop to get the array items two at a time.  I've attached a LabVIEW 7.1 VI to this post that shows how I would do it.  I'm sure there's a more efficient way to do it, but this one was the most straightforward to me (i.e., it was the first thing I thought of).

Hope this helps,

-D

 

Message 2 of 11
(4,256 Views)
Broken Arrow;

I am not sure if I understand your question. It is something like what I included in the picture?

Enrique


Message Edited by Enrique on 01-31-2006 10:32 PM

www.vartortech.com
Message 3 of 11
(4,257 Views)
Is this what you want:


Message 4 of 11
(4,244 Views)

Bravo, fahlers.  This is definitely the best approach.  I always forget about Typecast when I'm playing around with data representations.  🙂

-D

0 Kudos
Message 5 of 11
(4,239 Views)
Not quite as nice as fahlers, here's another variation of the theme. 😉
Message 6 of 11
(4,232 Views)
There's all great answers, thanks everyone. And I'm glad at least one person thinks it was "tricky". Smiley Happy
I would have never come close to Fahlers' answer, which is the most concise solution (although I don't understand how the For loop knows how many N loops to do!)  The other solutions make sense - it looks like I was overlooking the "String to Byte Array" function. It's not in the Array pallette, which I think is an oversight.
Thanks to all!
Richard






0 Kudos
Message 7 of 11
(4,213 Views)

The For Loop will iterate a number of times equal to the size of the array indexed into its border.  With fahlers' example, the array is half the size of the string length, since the string characters are grouped together two at a time when typecasting them to U16s (since a single character in a string is 8 bits, and a U16 is 16 bits).

-D

Message Edited by Darren on 02-01-2006 09:56 AM

Message 8 of 11
(4,197 Views)
Ah yes. The secret is in the U16 specification of the array that is "Type Casted" into the For Loop. EXCELLENT. Now I don't have to worry if I'm reading a 2k EEPROM or larger (my original idea had the for loop "hard wired" for the expected count). Thanks!
Richard






0 Kudos
Message 9 of 11
(4,173 Views)
Hi to all:

I just read the original post and tried to solve the problem my way. This is maybe a forgotten thread but anyway I did it. My method is shown in the picture. Of course less elegant than the other, but functional. I'm kind of new to the forums and I want to as active as possible. Smiley Very Happy

Regards.



Robst - CLD

Using LabVIEW since version 7.0


Download All
Message 10 of 11
(4,154 Views)