03-24-2016 02:11 PM
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!
03-24-2016 02:42 PM
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:
03-24-2016 02:42 PM - edited 03-24-2016 02:43 PM
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.
03-25-2016 01:42 AM - edited 03-25-2016 01:51 AM
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.
Edit:
Oops, you wanted strings... but maybe you wanted them converted anyway?