Arcade expression to display just the numbers of an address field

1268
5
Jump to solution
03-01-2021 08:32 AM
Labels (2)
KimberlyRieger
New Contributor II

Hello! Is there an Arcade function I can use that will display in the labels just the numbers in an address field? The address field that I have on a particular layer has the number and street name together. The labels I want to create for that layer just need the address number displayed. Thank you.

1 Solution

Accepted Solutions
jcarlson
MVP Notable Contributor

I don't know what your address data looks like, but assuming there's a space between the numbers and the street name, you could try using Split.

var addr = '1223 S Main St'

return Split(addr, ' ', 1)[0]

By including the limit argument, the function stops splitting after the first space and returns a single-item array, so we use "[0]" to pull out that value. The above code returns:

RESULT: '123'
TYPE: String

As long as the address numbers come first, this will consistently grab them, and won't give you odd results if a road has numbers in its name, such as 'Route 47'. The only time it wouldn't work is if you have a half address, like '4408 1/2 S Benjamin Rd'.

- Josh Carlson
Kendall County GIS

View solution in original post

5 Replies
jcarlson
MVP Notable Contributor

I don't know what your address data looks like, but assuming there's a space between the numbers and the street name, you could try using Split.

var addr = '1223 S Main St'

return Split(addr, ' ', 1)[0]

By including the limit argument, the function stops splitting after the first space and returns a single-item array, so we use "[0]" to pull out that value. The above code returns:

RESULT: '123'
TYPE: String

As long as the address numbers come first, this will consistently grab them, and won't give you odd results if a road has numbers in its name, such as 'Route 47'. The only time it wouldn't work is if you have a half address, like '4408 1/2 S Benjamin Rd'.

- Josh Carlson
Kendall County GIS
AdamLevine
New Contributor

John,
Along the same exact lines as the above example, could we use the Split function to grab the street name instead of the street number?  Anything after the space essentially. 

Thanks,
Adam Levine
SUNY Cortland

0 Kudos
jcarlson
MVP Notable Contributor

For sure! Again, assuming the data is consistently formatted, you could just use

return Split(addr, ' ', 1)[1]

 to get anything after the space.

- Josh Carlson
Kendall County GIS
0 Kudos
AdamLevine
New Contributor

John,
Thanks so much!
Adam

0 Kudos
KimberlyRieger
New Contributor II

Josh, that worked perfectly! thank you so much!