pad zeros

1131
2
04-03-2018 10:27 AM
ChristianRegosch
New Contributor

I am trying to insert a link into a pop up to a map about regional transit services. The url for all routes less than 100 have one or two zeros in front of the route number, ie 001 or 055. However, the route column on the attribute table only has the route number ie 1 or 55. Therefore, when I set the link to {Route} routes less then 100 come back with a 404 error. Is there anyway I can use an expression to pad it out with zeros or find another way to navigate around this?

Note, this live open data from our regional transit provider so I can't generate a a new column with the padded out route numbers.

Thank You!

0 Kudos
2 Replies
DanielSereno
New Contributor II

var myRoute = <your route field>

If Count(myRoute) == 1 {

   return concatenate('00',myRoute)

}

else {

   If Count(myRoute) == 2 {

      return concatenate('0',myRoute)

   }  

   else {

      return myRoute

   }

Plug the returned myRoute variable back into your URL.......Or, something like that. P.S. maybe add another "if" condition for properly formed routes, i.e. check for "Count(myRoute) == 3" just to make sure you are working with clean data.

Anyway, literally learning Arcade today and thought I'd take a crack at your question.

Thanks,

Dan

0 Kudos
DuncanHornby
MVP Notable Contributor

If you are using python to construct your string there is a nifty function called zfill().

myText = "9"
myNewText = myText.zfill(3) # creates 009
print myNewText
0 Kudos