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: 

Splitting a string based on delimiters

I am coding an application that captures an input string from a GPS device via the serial port.  I'm able to get the string just fine using VISA, my problem is with parsing through the string once I get it in memory.  Looking through the string pallet, I didn't see any functions available to split the string into each of it's components.  As an example, this is a NMEA sentence I pulled from the GPS device:

$GPVTG,0.0,T,0.2,M,17.4,N,32.2,K*4D

where:

$GPVTG,        The message for Track Made Good and Ground Speed
0.0,                 Course (in degrees)
T,                    Indicates True course
0.2,                 Magnetic course (in degrees)
M,                   Indicates Magnetic course
17.4,               Ground Speed
N,                   N = Knots
32.2,              Ground Speed
K                    K = Kilometers Per Hour
*                     checksum tag
4D                  sentence checksum

Currently, I can pull this string by using the "Match Pattern" string function - when I get the $GPVTG message, I get the remainder of the string.  After that, I pass the remainder of the string to the "Scan String For Tokens" function.  The problem here is that I have to index through the string based on where the comma's are located - and they are not always in the same spot.  For example, if I wanted to get "Ground Speed" in Knots, based on the string above I would begin indexing at location 12 (assuming that index 0 begins at the very first comma).  This would work - however Course will not always be 0.0 - it could be 256.0 which then changes the index location of what I think is the beginning of Speed in Knots.

Here's my question - is there a function in LabVIEW that splits a string into an array of strings based on delimiters (such as a comma)?  I've used such a function in C# .NET - and it works great for what I want to do, but the string functions pallet doesn't have anything like this.  If there is no such thing as a split string into an array of strings - how could I go about making one?

I'm using LabVIEW 7.1 Developer Suite on a Windows XP box.

Thanks in advance for any help!
0 Kudos
Message 1 of 5
(3,641 Views)
Hi Max
 
This is how I would do it.
Hope it helps.
 
Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
Message 2 of 5
(3,634 Views)
Here's a way of doing it.

Edit:  Oops, looks like I was beaten to it!

Message Edited by Novatron on 09-02-2005 09:47 AM

0 Kudos
Message 3 of 5
(3,633 Views)
Or just use the Spreadsheet String to Array.
0 Kudos
Message 4 of 5
(3,625 Views)
Thanks ya'll - good feedback on a relatively simple problem.  I got your idea to work Thomas - and it's pretty easy.  Now all I have to do is get the serial port to work the way I need it to - it drops some of the NMEA messages once in a while.  Add that to polling for data on a USB-6008, and things start to get out of whack.  Thanks again!

tsc
0 Kudos
Message 5 of 5
(3,609 Views)