In ArcMAP 10.2, I am trying to format the labels on my map.

If the label is

1402 Bowie Road

But I want only to display numbers:

1402

What is the expression to create this?


  • 1
    I'm not sure if 10.2 is different to 10.1 in this respect but you can do this using advanced label options.. use var = split(field," ") and label using var[0] which is the first item in the list. – Michael Stimson Apr 7 '14 at 2:41
  • 1
    alternatively in VB use left( [field], instr( [field] ," ")) to return just the first word of a sentance. – Michael Stimson Apr 7 '14 at 2:44
  • The split operation can be done in one line with VB Script. To get the first word before the first space use: split(field, " ")(0) – Richard Fairhurst Oct 1 '14 at 16:18

You can put this as the label expression for the feature:

def FindLabel(yourField):
    if yourField is not None:
        split_field = yourField.split(" ")[0]
        return str(split_field)
    else:
        return None

Using Python as the parser and checking the Advanced box.

Replace yourField with whatever field you are using to label.

An alterntive to ian's suggestion, you can change your label expression to something like the following. By importing the regular expression module, you can create function to only display numbers at the beginning of a string.

def NumberLabel(addressField):
    import re
    return re.search('^\d*', addressField).group()

As per Ian's example, use python as the parser.

This will return the number at the beginning of a string.

1402 Bowie Road will return 1402     
123 Main Street will return 123     
123 Main Street Unit 4 will return 123    
515 4th Avenue will return 515    
613Main Street will return 613

Note that last example does not have a space after the number yet still returns the correct result.

Another alternative to both Ian and Fezter's answers is to use the INSTR and MID VB script functions (This particular expression does not require you to be in an Advanced Expression mode):

MID([Your_Field], 1, INSTR([Your_Field]," "))

INSTR function has the following parameters: InStr([start,]string1,string2[,compare])

MID function has the following parameters: Mid(string,start[,length])

Square brackets indicate optional parameters

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.