LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

splitting up a string into seperate elements

Hello, I am receiving data in strings from the serial port, however I would like to split up the strings into seperate elements- each element in the string is divided by \s, and the end of the string has \r\n. I'd like to put the data in an array with the dimension number being the number or elements the strings- 7. How can I do this? Thank-you!
0 Kudos
Message 1 of 16
(8,199 Views)
First, use the Search and replace string function using \r\n as the search string and an empty string as the replace string. Next use the Spreadsheet string to array function with \s defined as the delimiter. This will give you an array of strings. Both of these are found on the string pallette. This method will work even if the number of elements in your data string changes.
0 Kudos
Message 2 of 16
(8,199 Views)
"Spreadsheet string to array" will convert it to a numeric array, which is only appropriate if you are dealing with numbers only. I assume you want an array of strings as output.

If there are always exactly 7 elements, you could just blindly use a FOR loop as in the attached example. If the number of elements is variable, just add a bit of logic to detect the end of the string.
Message 3 of 16
(8,199 Views)
"Spreadsheet string to array" is a polymorphic function which works with strings as well as numbers as in the attached example (version 6.1).
Message 4 of 16
(8,199 Views)
Ahh .... I don't remember seeing that, but it makes sense. 😉
Isn't LabVIEW cool?
0 Kudos
Message 5 of 16
(8,199 Views)
I am doing a similar task, and used the VI you provided.
Using this, each piece of data is seperated.
How can I index each one, so I can send that data to the appropriate place?
For example, if the 5th one is my O2 measurement, how can i pull only that number out so I can do something with it?
Cory K
0 Kudos
Message 6 of 16
(7,861 Views)

Use the Index Array Function.

Array functions are LabVIEW fundamentals.  I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 7 of 16
(7,834 Views)

And more training here:

To learn more about LabVIEW, I suggest you try looking at some of these tutorials.
You might also try having a look at these video tutorials..

R

0 Kudos
Message 8 of 16
(7,827 Views)

 

Thank  you

 

Just what I was looking for. I was familiar with this in VB.net but not in labview.

 

Here is a snippet of my code. The reference came from local variables when snippet was made.

 

The function is to read a text file written by another application. Basically arguments that I'm reading from a text file instead of reading them from the command arguments.

 

I did not need the replace VI.

 

Thanks and I hope this help

JCollado
0 Kudos
Message 9 of 16
(7,604 Views)

 


@JCollado wrote:

 

Here is a snippet of my code. The reference came from local variables when snippet was made.


 

You still make quite a few mistakes and add unnecessary complexity.

 

  1. Never operate on paths as strings!!!  Use "build path" as shown.
  2. To read the entire file, you can use the atomic read function (top image). No need to open, measure, read, close. Even better, Use "read from spreadsheet string" (bottom image).
  3. To get successive elements, you don't need to wire the indices.

Message 10 of 16
(7,564 Views)