LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

search and replace string function

Hello, I am using the "search and replace string" function and it does nt seem to work consistently for me.   I am using it in a situation where I am taking an array of strings, converting this into a spreadsheet string then deleting all of the commas.  Has anyone experienced the same behavior? I have searched through other posts and found other simular faults but none of the fixes worked for this. I can post the code it needed.
 
Thanks,
 
 
 
Andrew
0 Kudos
Message 1 of 15
(3,794 Views)

update:

 

 

This does not occur though, if I run it with highlight execution on or if I just run it with a "static" array not one that I am acquiring in a previous step.  I have tried to put a large time delay in play to emulate the effect of highlight execution, and to also give extra time for the array to be stored,  but this did not work either.

0 Kudos
Message 2 of 15
(3,785 Views)
Do you have something against commas? Smiley Very Happy

Seriously, though, what exactly is happening? You didn't say what happens, nor what version of LabVIEW you're running, so it's kind of hard to say what's happening. All you said is that it doesn't work consistently. Please post your code.

As an aside, based on your description, are you just trying to concatenate the elements? If so, you can just wire the array of strings into a "Concatenate Strings" function as shown below:


Message Edited by smercurio_fc on 05-15-2007 09:10 AM

0 Kudos
Message 3 of 15
(3,786 Views)

Yeah I have something against comma's 😛  in this case I am looking for specific message content coming back from a decoder which replicates a satellite reciever.  Part of my code builds an array with all of the data received from the reciever, and the other part takes that array converts to a spreadsheet string then uses this funtion first to delete all of the commas in the string, then I use it as a search function by "replacing" the message that I am looking for.  I do this because the string could have numerous instances of the same message and so I just use the "number of replacements" output as a pass/fail criteria.  Here is a screenshot of the code:

 

 

 

 

0 Kudos
Message 4 of 15
(3,777 Views)
Forgot to include the LV version although if you look at the error clusters its a dead giveaway 🙂 its 8.2
0 Kudos
Message 5 of 15
(3,771 Views)
You are replacing commas that are in the original strings? You're not adding any commas with the Array to Spreadsheet String function.
0 Kudos
Message 6 of 15
(3,760 Views)
I agree that commas are often not desirable, especially if your software should also work in countries where comma is used as a decimal seperator.
 
Where are the commas coming from? Does (1) each element of the original array have one (or more), do you (2) use comma as seperator if you convert it to a spreadhseet string?
 
For (1), you might just strip out the comma for each element right in the loop. For case (2) you would simply use a different separator to begin with, of course. 😉
 
Btw: you are abusing a WHILE loop as a FOR loop, because you have a fixed number of iterations. Please replace it with a FOR loop. If you use a FOR loop, LabVIEW can manage memory much more efficiently, because it can allocate the entire output array before the loop starts. For While loops, the total number of iterations is not known to the compiler. (Of course a real program would also stop the loop if an error occurs. In this case you would need to stay woth the WHILE loop. :))
 
Do you have a simple example how the raw array elements look like. How many commas are there?
0 Kudos
Message 7 of 15
(3,752 Views)
Indeed Dennis, that's the first thing I saw when I looked at the code. Also, you're running a while loop with a fixed number of iterations. That's a for-loop. Use that instead.

You can still use the concatenate string trick I showed you above to accomplish what you're doing. However, there are other methods. For instance, you can use the Search 1D Array function to search your array of messages for the message that you're looking for. Just put this in a loop to count the messages in the list. Also, you can head over to the OpenG web site and get their OpenG Array library. You can use the "Filter 1D Array" to filter out the message you're looking for, and simply compare array sizes:





Note: slight cross-post with altenbach regarding for-loop.


Message Edited by smercurio_fc on 05-15-2007 10:30 AM

0 Kudos
Message 8 of 15
(3,751 Views)

There are a ton of commas per line (30-50 ish depending on the message length).  The data that comes back from the reciever is commas seperated for every one of its critera, and then again every 2 bytes in the message content.  I did try to use the commas as the delimiter in building the spreadsheet string, but it still did not help.  In response to the while loop abuse I added a function that scans the incoming strings for length, so it now is controlled by if a message of or greater than a specific length is found, or x number of iterations pass, then stop the loop.

I found a work-around.....but it is kinda of hookey.....if I write the data from the while loop into a global variable, then read from the variable the code works fine, I tried it over and over and it seems to work.....I don t really like this approach though and I am open to a better solution if anyone has an idea.  I do not change anything else with the code other than split the data line to a varible and read back that variable.   Would this help only because the data is "forced" to be written to memory in sequence?

 

Andrew

0 Kudos
Message 9 of 15
(3,743 Views)


@labstew wrote:
I found a work-around.....but it is kinda of hookey.....if I write the data from the while loop into a global variable, then read from the variable the code works fine, I tried it over and over and it seems to work.....
OK, that makes so litttle sense, it's scary! Can you show your code?
0 Kudos
Message 10 of 15
(3,741 Views)