03-25-2022 07:53 PM - edited 03-25-2022 08:24 PM
Hello, I'm trying to write a VI that parses a given string into substrings and displays the results in a cluster using Keys and Fields.
I created a VI that separates the strings and put them into clusters, but it's not using Keys and Fields. Everything I find on the topic is complicated and I don't understand.
I need to be able to
03-25-2022 08:37 PM
Handling them in any order seems like an unreasonable constraint to me. Data like this are always going to be arriving in order.
03-26-2022 07:24 AM
@billko wrote:
Handling them in any order seems like an unreasonable constraint to me. Data like this are always going to be arriving in order.
Not necessarily, some of the data may simply change. Assume Emma contracts COVID during a hospital stay recovering from mastectomy / addadictomy surgery over a birthday. Eric, now identifies as Male and aged to 37.
And here is where we point out the advantage of using bundle by name instead of bundle and extracting the keys from the array of K-V pairs in a loop.
03-26-2022 10:51 AM - edited 03-26-2022 10:55 AM
Here's a quick example (even returns some sentinel values for missing fields):
There are many other ways to do this, of course.
Original order:
Different order, same result:
03-26-2022 12:57 PM
@JÞB wrote:
@billko wrote:
Handling them in any order seems like an unreasonable constraint to me. Data like this are always going to be arriving in order.
Not necessarily, some of the data may simply change. Assume Emma contracts COVID during a hospital stay recovering from mastectomy / addadictomy surgery over a birthday. Eric, now identifies as Male and aged to 37.
And here is where we point out the advantage of using bundle by name instead of bundle and extracting the keys from the array of K-V pairs in a loop.
I thought the OP meant truly random, like keys sometimes arriving before the associated values or sometimes after.
03-26-2022 01:03 PM
@billko wrote:
I thought the OP meant truly random, like keys sometimes arriving before the associated values or sometimes after.
If the values not follow their key, all bets are off. 😄
03-26-2022 01:34 PM
Another possible solution is to use a regular expression to capture key value pairs, and insert them into a map where you can dereference them later. You could do this explicitly like in the snippet below, or you could index the map into a For Loop. When you do that, the keys are indexed alphabetically (for strings).
This also works for any order, and as long as you maintain the map for each person, then it could work for partial data as well.