Efficient way to change state abbrev to full name


#11

Once you’ve typed the full expression with all states, please share so others don’t need to do the hard work as well :smile:


#12

@bobbles I posted the piston above. Use m4v3 to import it


#13

Just an extra thought, and I’m not 100% if this will be a problem or not… but it’s possible that the replace function might change words containing the abbreviations unintentionally, such as changing the word ‘are’ to ‘Arkansase’

Might be worth doing a few tests before you spend time typing out the whole lot!

If it does cause a problem, maybe replace the leading and trailing spaces as well:

replace(message, ‘ IL ’, ‘ Illinois ’, ‘ AL ’, ‘ Alaska ’, ‘ AR ’, ‘ Arkansas ’)


#14

One more approach, you can try a nested ternary… (short list below)

(sC == “AL” ? “ALABAMA” :
(sC == “AK” ? “ALASKA” :
(sC == “AZ” ? “ARIZONA” :
(sC == “AR” ? “ARKANSAS” :
(sC == “CA” ? “CALIFORNIA” :
(sC == “CO” ? “COLORADO” :
(sC == “WY” ? “WYOMING”)))))))


#15

What’s ‘sC’?

The message string contains more than just the abbreviated state, so I don’t see how a ternary operator could pick out the correct part to work on?


#16

this should return the long form of state:

define string shortState = 'AL,AK,AZ,...'
define string longState = 'Alabama,Alaska,Arizona,...'

arrayItem(indexOf(shortState, lookupState), longState)


#17

Oh, I was feeding it the state code == sC

And there’s @bangali’s method, Lists which I have not learned very well yet :slight_smile:


#18

before trying that one please check if indexof supports comma delimited string :slight_smile:

this does not actually use lists just comma delimited strings


#19

Thanks for the code.
The 2 global variables that you are using, what type are they?


#20

@bangali I’m getting an array out of bounds?


#21

@bobbles they are dynamic. They are my api key for google maps, 2 different ones, and a dynamic one for my home gps latitude and longitude


#22

yeah indexof may not support comma delimited string try this:

define string shortState = 'ALAKAZ…'
define string longState = ‘Alabama,Alaska,Arizona,…’

arrayItem((indexOf(shortState, lookupState) / 2), longState)

this will require checking none of the short state cdoes are inadvertently generated by stringing them together.


#23


#24

try this:

note the trailing comma is needed.


#25

I’m not sure how arrayIyen can help in this case… the OP wants to replace the abreviation which is mixed up within a longer string of text generated from elsewhere…


#26

thought OP was asking for this?


#27

Look at his message variable and clarified request in post 3


#28

I think I almost got it. It may not be most beutifu; but I will post my final working and then maybe one of the fine people here can help me get it effecient


#29

thought post 6 was later and more updated.

doesnt matter though same principle applies.

used 3 lines instead of 2 for readability.

heres the one liner :slight_smile:


#30

Ok guys. Thanks for the help.

Here is a green shot and a screen capture of the piston. It’s working as I need. Just a lot of manipulation to get the state on there rather than the abbreviation.

Any suggestions to make this even cleaner. I’m all ears