Token function

835
2
02-27-2012 09:17 AM
HeatherCarlos
New Contributor III
Hello,
I need to parse some street addresses (stored as strings in one attribute field) to 2 separate fields ??? one for the house number, one for the street name.  Of course the addresses have varying lengths of house numbers (or sometimes none) and varying lengths of street names (and varying word count), so I can???t just use Left() or Right().  For example:


1 Main St
10 Main St
100 Maine Street
100 Main Podunk St
Podunk St  

I think I need to tokenize the string with the space as a deliminator, but I've never used python (and only basic VB scripts), so I'm getting lost as I troll through the various python resources.  Can someone help me out - I'd like to do this in the field calculator.

Thanks,
Heather
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Heather,

You can accomplish this using the Field Calculator and the 'split' method.  Example:

!FullAddr!.split(" ", 1)[0]


Where 'FullAddr' represents the field name containing the address.  The above will return the house number.  To return the street name you would specify:

!FullAddr!.split(" ", 1)[1]


Be sure 'Python' is checked at the top of the Field Calculator.

[ATTACH=CONFIG]12255[/ATTACH]
0 Kudos
HeatherCarlos
New Contributor III
Thanks so much, worked like a charm.

Some day I'll make the time to work through a python course, would save me so much time!

Thanks,
Heather
0 Kudos