Parsing actionscript parameter

Hey guys, it’s been years, and I am no better at relevance :slight_smile: I have an action parameter where the console operator is entering a four digit store number. ie. 1246 or 0875. If the four digit number contains a leading 0, I need to strip it off, and save that three digit number as another parameter to use in my actionscript. I have been looking, but haven’t found anything that is working. Any help would be appreciated, thank you in advance.

This is what I have so far, which definitely is not working at the moment, still looking.

parameter “storenum” = "0841"
parameter “storenum2” = “{if{(first 1 of {parameter “storenum”} = “0”)} then {(last 3 of {parameter “storenum”})}}”

Thanks for posting what you have tried so far, an example goes a long way toward understanding where you are stuck and where we can help.

To understand the edge cases, would you want to trim all of the leading 0’s, or just the first one? What result would you want if the user entered store “0001” ?

Looking at this line, I’ll break apart where I see some issues

The first thing is that there are multiple sets of curly-brackets, which would confuse the parser. You need just one set of curly-brackets, which itself wraps up the entire Relevance clause and has one single answer. To start with, I’d remove the extra curly-brackets and end up with

parameter "storenum2" = "{if (first 1 of parameter "storenum" = "0") then (last 3 of parameter "storenum")}"

However, in Relevance, an if/then/else … must contain an “else” clause. If the string does not start with a “0”, we’ll want storenum2 to keep the original four-character string, so that changes to

parameter "storenum2" = "{if (first 1 of parameter "storenum" = "0") then (last 3 of parameter "storenum") else parameter "storenum"}"

Based on the scoping, I don’t think the parentheses are strictly required either. They help to understand the flow of where the if/then/else clauses are separated, but after checking in the fixlet debugger I can verify this is also valid:

parameter "storenum2"="{if first 1 of parameter "storenum" = "0" then last 3 of parameter "storenum" else parameter "storenum"}"

As usual, there are several ways of writing Relevance. I personally don’t like repeating parameter "storenum" in three places, though it’s mostly a matter of style. I like having a repeating pattern that allows me to reference parameter "storenum" just once, which makes it easy to replace that with a different parameter the next time I reapply a pattern like this. So I would suggest

parameter "storenum2"="{(if it starts with "0" then following text of first "0" of it else it) of parameter "storenum"}"

It’s also worth pointing out, that if you’re to trim all of the leading “0” characters, you can do that by converting the parameter from a String to an Integer via a casting. In Relevance, casting to an integer will strip the leading ‘0’ characters, while in ActionScript the ‘parameter’ assignment will automatically convert that result back into a string for storage or for when you reference ‘parameter “storenum2”’ later in the actionscript.

parameter "storenum2"="{parameter "storenum" as integer}"
4 Likes

Thank you sir, just what I needed, and I appreciate the explanation as well. Thank you

1 Like

Just wondering if there was another approach by appending a leading “0” then parsing the text after the last “0” which would drop off any leading 0, be there 1 or 2 of them

parameter "storenum2"="{following text of last "0" of ("0" & parameter "storenum")}"

Edit: Ditch that idea, easier to cast to integer as @JasonWalker already shows :blush:

4 Likes