From 11:00 PM CDT Friday, May 10 – 02:30 PM CDT Saturday, May 11 (04:00 AM UTC – 07:30 PM UTC), ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there an easy way to replace individual elements in one string array from another striing array?

Solved!
Go to solution

I have a string array with elements as follows:

 

   00 00 00 00 00 00 00 00

   00 00 00 00 00 00 00 00

   00 00 00 00 5E 00 00 00

   00 00 50 00 30 00 33 00

   34 00 39 00 00 00 00 00

   00 00 00 00 00 00 00 00

   00 00 00 00 00 00 00 00

 

The array I want to use to replace values with is:

 

43 4E 31 30 30 33 30 30 31 41

 

Where 43 goes in the 3rd row fifth position

Where 4E goes in the 3rd row seventh position

Where 31 goes in the 4th row  first position

Where 30 goes in the 4th row third position

Where 30 goes in the 4th row fifth position

Where 33 goes in the 4th row seventh position

Where 30 goes in the 5th row  first position

Where 30 goes in the 5th row third position

Where 31 goes in the 5th row fifth position

Where 41 goes in the 5th row seventh position

 

So the final array looks as follows:

 

   00 00 00 00 00 00 00 00

   00 00 00 00 00 00 00 00

   00 00 00 00 43 00 4E 00

   31 00 30 00 30 00 33 00

   30 00 30 00 31 00 41 00

   00 00 00 00 00 00 00 00

   00 00 00 00 00 00 00 00

 

Is there an easy way to replace an element of a string within an array with another element of a string within a different array?

 

Thank you.

0 Kudos
Message 1 of 13
(2,715 Views)
Have you tried the 'replace array subset' vi? This lets you replace rows, columns or specific elements etc in array
David
www.controlsoftwaresolutions.com
0 Kudos
Message 2 of 13
(2,711 Views)

With the replace array subset I was only able to replace an entire row in my array, not just a single element.

0 Kudos
Message 3 of 13
(2,708 Views)

I've attached the concept for one approach, but it seems like there should be a better method.

 

 

0 Kudos
Message 4 of 13
(2,695 Views)

chuck72352 wrote:

With the replace array subset I was only able to replace an entire row in my array, not just a single element.


Not true. Re-read the documentation on that function.

 

Now try to re-write your VI...

0 Kudos
Message 5 of 13
(2,688 Views)

My array is 1D, which I believe means each row is a single element. If I understand the documentation correctly for the "replace array subset", I can only replace an element, not a portion of a single element.

 

For example in my array, a single element might be:   01 02 03 04 05 06 07 08. Therefore I could replace it with 01 01 01 01 01 01 01 01 for example, but I dont see a way to for example change only the 03 to for example 0A without replacing the element with 01 02 0A 04 05 06 07 08.

0 Kudos
Message 6 of 13
(2,680 Views)
You might find it simpler to convert to a 2D array (which is the way you have your situation drawn).  Using "Spreadsheet String to Array" with the delimiter set to [space] will make this easier.  With a 2D array you could do the replacements easily.  Otherwise you'll need to extract one line of your array, use Replace Substring to replace just the characters you want, and finally put the modified string back into the array.
Message 7 of 13
(2,670 Views)

Nathand,

 

Thank you, that's kind of what I thought, I was hoping that there might be a better approach.

0 Kudos
Message 8 of 13
(2,667 Views)

Try this

 

Omar

Message Edited by Omar II on 03-24-2010 03:25 PM
Omar
0 Kudos
Message 9 of 13
(2,659 Views)

It's not quite working. Output array 2 has blanks in the positions where characters are expected.

0 Kudos
Message 10 of 13
(2,646 Views)