LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to Substring to Cluster

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

  • parse the sentence case-insensitively
  • handle the keys and fields in any order
  • extract substrings into a cluster

key block.pngkey front.png

0 Kudos
Message 1 of 7
(1,137 Views)

Handling them in any order seems like an unreasonable constraint to me.  Data like this are always going to be arriving in order.

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.
0 Kudos
Message 2 of 7
(1,118 Views)

@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.


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 7
(1,073 Views)
  • The order and name of cluster elements will not change (make it a typedef to be sure!), but the order of key/value pairs in the input string might, depending on where it is coming from.
  • Don't use array to cluster!!! That's completely pointless here
  • Create the cluster by looking up the desired fields in an array of keys, then process accordingly (string, decimal, boolean, etc.)

 

Here's a quick example (even returns some sentinel values for missing fields):

 

altenbach_0-1648309803788.png

 

There are many other ways to do this, of course.

 

Original order:

 

altenbach_0-1648309927407.png

 

Different order, same result:

 

altenbach_1-1648310019511.png

 

 

0 Kudos
Message 4 of 7
(1,064 Views)

@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.

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.
0 Kudos
Message 5 of 7
(1,050 Views)

@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. 😄

0 Kudos
Message 6 of 7
(1,046 Views)

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).

 

Key Value Pairs.png

 

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.

 

Key Value FP0.pngKey Value FP1.png

 

Wes Pierce
Principal Engineer
Pierce Controls
0 Kudos
Message 7 of 7
(1,038 Views)