LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Match Pattern function to find and display specific substring

I'm taking a string of data from a sensor, and I need to parse the string into three different strings.

 

Here's an example of the string:

0 106 13 21.0 C 1002.0 mbar 40.7%

 

At it's fullest, it's 34 bytes long.  I'm looking to extract the temperature ("21.0" here), pressure ("1002.0") and relative humidity ("40.7").  To do so for the temperature, I'm using the match pattern and searching for the C.  How can I get the function to return only the "21.0"?

 

The closest I've gotten is this: I search the substring for "[~3]+[C]", and it will return "21.0 C".  I need that, but without the C.  

 

Can anyone help me figure out how to search the string more effectively?  I don't understand how to manipulate the special characters.

 

Thank you!

0 Kudos
Message 1 of 4
(6,460 Views)


There's more than one way to skin a cat.

 

I tend to use the match string funstion in a pretty rudimentary fashion, as it is not as difficult to use (you don't have to remember pattern matching codes, which can be pretty inflexible). In your case, you have three unique strings in your code, which you can use to parse out the three values you want. 

Another possibility is to parse this string into an array based on the separator, which is your case is a space. Then your temperature is the fourth item in the array. But I'd use the string to fraction number funciotn, with the offset index of "9", as long as this number always appears in the same place in the string. See my examples:

 

parse string.png

_____________
Creator of the BundleMagic plugin for LabVIEW!
0 Kudos
Message 2 of 4
(6,438 Views)

Here is what I came up with.  It uses the Match Regular Expression to find a number before the string you supply and then Search/Split String to remove the extra string.  Put it in a FOR loop in order to do the search for all of the values you want.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 4
(6,436 Views)

I took a different approach.  This just parses the whole thing out.  I mean, you may as well get everything.  You don't have to hook up the stuff you don't want.  If you feel the need for the units parts, you can just substitute the actual text with %s in the format string and add the appropriate outputs - but if you give the outputs meaningful labels, you probably don't need the units.

parse stuff.png

Edit:

Oops, you wanted strings... but maybe you wanted them converted anyway?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 4 of 4
(6,388 Views)