ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

delete repeated line in string?

pretend string input is

1
2
2
3
4
4
4
5
6
6

how do i make it so output is

1
2
3
4
5
6

?

Message Edited by unknown00 on 06-29-2007 03:09 PM

0 Kudos
Message 1 of 8
(3,624 Views)
This should be a pretty simple algorithm.

Start with empty array of strings.
1. Read line.
2. Check if line already exists in array of strings.
3. If not, add line to string array. If it does already exist, do nothing.

Repeat 1-3 for all lines. When done, concatenate each string in the array into your output string.

Let us know which of these steps you might be unsure about.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 8
(3,615 Views)
hmm i guess i was doing a different approach. i was trying to scan a line and the next one and compare those 2, but your way makes more sense. how would i check if it already exists? loop through whole thing and compare?
0 Kudos
Message 3 of 8
(3,611 Views)
If you have an array of strings you've processed so far, then use the Search 1D Array function in the array palette. It will output either the index where the element you're searching for is found, or -1 if it's not found.
Jarrod S.
National Instruments
0 Kudos
Message 4 of 8
(3,606 Views)
i apologize for my stupidity 😞 as always please help
0 Kudos
Message 5 of 8
(3,601 Views)

This should help. Step through it, see what happens. Probe everything.

 
Jarrod S.
National Instruments
0 Kudos
Message 6 of 8
(3,595 Views)


@unknown00 wrote:
i apologize for my stupidity 😞 as always please help

There are a couple of bad decisions in your code that might make it difficult to troubleshoot.

  • Your shift register for the position is not initialized, meaning the VI will only work the first time you run it. Make sure you start at zero.
  • Your "\n" constant is in normal display, meaning you'll get the string "\n" instead of a linefeed. Set the indicator to \-codes and delete the extra "\"

Many decision depend on the fact if your lines are sorted or not. Are they? They are sorted in all your examples above!

Here's a quick draft of two possibilites. The first builds on your original VI with most bugs removed. It assumes that the lines are sorted. The code below operates on a sorted numeric array. Have a look! 🙂 There are many other ways to do this.

How many lines do you need to process?

Message Edited by altenbach on 06-29-2007 03:31 PM

0 Kudos
Message 7 of 8
(3,590 Views)
Yet another solution is to use the handy-dandy "Remove Duplicates From 1D Array" VI from the OpenG Array library.
0 Kudos
Message 8 of 8
(3,586 Views)