Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How do search and rearrange a string in labview

I have a string which is somewhat as follows:
 
-101   1
-102   1
-130   1
-190   0
-230   0
-400   1
-402   1
 
and so on............. I need to read this and split this when the 1 ends (second column) and the zero starts................Again I need to split this when the 0's end and so on.... The length of this string varies. So i do not know the number of entries.... COuld anyone help me out with this....... Thanks a million..........
0 Kudos
Message 1 of 7
(4,484 Views)
Before the help comes...
 
Is the string always the same length ?
Is there always a (1 or more) space between the numbers ?
Does the string never start with a space ?
 
Split the array into what ? New arrays ?
 
Did you already tried to make something yourself ?
 
What version LV do you use  ?
 
0 Kudos
Message 2 of 7
(4,449 Views)
Split the array into what ? New arrays ?   must be: Split the string into 1D array of strings ?
0 Kudos
Message 3 of 7
(4,447 Views)
Hey thanks for your prompt reply KC....... Really appreciate it...........
 
 
This what my string looks like right now.....
 
-101   1
-102   1
-130   1
-190   0
-230   0
-400   1
-402   1
 
I want it to look something like this:
 
-101   1  -190  0  -400 1
-102   1  -230  0  -402 1
-130   1
 
The string splits at 1 and again at 0. This is what the final document should look like.....
0 Kudos
Message 4 of 7
(4,445 Views)
Hello,
 
It looks to me like you've got a somewhat complicated string parsing algorithm here to implement. Something you might consider is using a table to help you organize your data. A table in LabVIEW is nothing more than an array of strings -- typically a 2-D array of strings. If we start with the string you originally posted, we can convert this into a 1D array of strings. One way you could accomplish this is by using the Match Pattern VI to identify where each of the new line characters ('\n') are in the string.
 
From here, you can use array manipulation VI's to organize your 2D table. Scan through each each cell in your original 1D array of strings. As you come to a different termination number (0 or 1) you can begin a new column in the table.
 
There are of course several ways you could implement an alogorithm to parse your data. I only offer a table a suggestion. You'll have to flatten it all back into a single string if you wish, but I'll leave these decisions to you. If you have more specific questions, I'm happy help answer them.
 
Thanks!
Charlie S.

Visit ni.com/gettingstarted for step-by-step help in setting up your system
0 Kudos
Message 5 of 7
(4,423 Views)

Hi,

Are you sure you want it in one string like you said. If you have a lot of data it will get very wide.

Just asking to avoid making the wrong VI for you. It can be limited to 10 columns or ...

0 Kudos
Message 6 of 7
(4,419 Views)
How's that ?  Smiley Wink
0 Kudos
Message 7 of 7
(4,407 Views)