How to create a name:value pair for lookup?


#1

I am trying to create a table of name:value pairs in a variable and then look that up when a parameter is passed into piston so I can send a SMS message when the name is located. In Java/groovy this would be pretty simple but I can’t seem to find a way to do this.

Does anyone have some sample code that demonstrates the variable assignment and lookup?

Thanks.


#2

Maybe you can use this as a springboard. It basically looks for a state abbreviation and returns the full name.

Theoretically that should work, or get you started in the right direction,


#3

Beautiful code @Gopack2, but why is it only 49 steps?


#4

50 states, but starts at 0, or I missed a state, lol


#5

That was it… You must not be a fan of Massachusetts, LOL


#6

Lol your right, missed that one… fixed for those that may need it.

I guess you could theoretically use this to write your own contact book… the send messages to your contacts using the result


#7

I could see this piston being handy in reverse as well…
To have shorter (friendly) names displayed instead of long named devices…


#8

Yes two string arrays should work as long as the index stays in sync. Not as elegant as a index:value pair but does work. Already coded it into my piston…thanks…


#9

You could try to parse a variable as json, that might work as you originally intended


#10

Yes that wold be the best approach just need to figure out a good way to code. Because I only have 6 elements using the array method isn’t that bad but if the list grows to say the example of 50 states I would defiantly look at Jason encoding.