01-29-2020 06:09 PM
Very quick question to bother you guys with. I want to be able to use the match pattern to parse the response from my device and see if the response contains either "x =" or "f =" with the white space in the middle. I then want to take everything after that and use it. Is that easy to do with Match Pattern, and what would that look like? In other words, is it just like any regex and how do I do I make the first character variable in regex? Thank you.
Solved! Go to Solution.
01-29-2020 09:14 PM
I'd say that "[xf]\s=" ought to do it.
[xf] matches any character between the square brackets. Here it will match 'x' or 'f'
\s matches a space character
= matches an equals character
An alternate to cover upper and lower case as well as a variable # of spaces: "[XxFf]\s*="
-Kevin P
01-29-2020 09:24 PM
The only change I would make to Kevin's pattern is "([xf])\s=" to capture the initial part so you can use that in a case diagram if you want different behaviour.
01-29-2020 09:25 PM
This is fairly simple, if you have any experience with strings, know how to use LabVIEW Help, understand how to use loops (and conditional indexing or concatenating tunnels) along with shift registers to "take apart" (or "parse") data.
Why don't you start by using one of the Pattern Matching routines in LabVIEW (read its Detailed Help for ... detailed help)? If you attach some code (runnable VIs, please, no static pictures) showing what you are doing, and show the search string(s) you think would be useful, we can comment and help you with the one or two things you might have missed ...
Bob Schor
01-29-2020 10:47 PM - edited 01-29-2020 10:59 PM
This is what I came up with, but it doesn't work correctly yet. I set match pattern to look for the '=' and then grab that because I know the response I'm looking for will always have that. The problem is when I get that value the switch case to determine whether it is a response with the '=' in it or not seems to just not display anything in the "Measurement 2" Indicator. Not sure why. Earlier displaying every response even with the switch case but it's supposed to be the output of match pattern.
01-29-2020 11:11 PM
Your case diagram was obviously connected to a boolean originally, and now it is a string trying to match the values "True" or "False". Perhaps you should try changing "True" to "" (empty string) and remove Default Case, and change "False" to Default Case, to get started.
01-29-2020 11:32 PM
...... and get rid of the select statement.
01-30-2020 09:59 AM - edited 01-30-2020 10:06 AM
01-30-2020 12:04 PM
Thank you all. I'm now using the regular expression and it works but only for the first instance of the loop. I will have to get back to guys when I figure that part out.
01-30-2020 01:57 PM
Here are a few suggestions to help you write code that is easier for you (and us) to understand:
You mention a problem with a loop in parsing your string. I did not see this in the code you attached.
Bob Schor