Select to view content in your preferred language

How to label feature by using part of the field values

3526
3
Jump to solution
10-10-2019 12:18 AM
Liliaaaaaa
Occasional Contributor

Hi guys, I have to label all the cables by using all the highlighted numbers from the 'Identifer' field as screenshot. I don't want to create another filed so would like this to be done in label expression? Any fabulous suggestion?

(the number is always start in the 21st word, but ends either the 22nd or 23rd, for example, if the value is "4200-SUB-LUK014-3H1-2", then I just want to label the feature as "2"; if  the value is "4200-SUB-LUK014-3H1-36", then I will want to label the feature as "36".)

0 Kudos
1 Solution

Accepted Solutions
Liliaaaaaa
Occasional Contributor

Thank you Ken, I have also figure in Python, just write down if anyone needs it.

  1. After opening the label Expression window in the label tab of ArcMap, please tick Advanced in the expression and choose Python in the Parser.

 

  1. Please paste the following script into the Expression window:

 

def FindLabel ([Identifier]):

    s = [Identifier]

    return s[20:]

 

  1. The [Name] field is the column that you want to label with.

 

  1. The [20:] in the script means choose the string start from 21st and to the last character of the cell value. If you want to start from another location, just change the “20” in the script.

 

 

View solution in original post

0 Kudos
3 Replies
KenBuja
MVP Esteemed Contributor

Use the Split function

Function FindLabel ( [Identifier] )
  dim values
  values = Split( [Identifier] ,"-")
  FindLabel = values(UBound(values)) 'This returns the last value. If it's always the same format, just use values(4)
End Function
Liliaaaaaa
Occasional Contributor

Thank you Ken, I have also figure in Python, just write down if anyone needs it.

  1. After opening the label Expression window in the label tab of ArcMap, please tick Advanced in the expression and choose Python in the Parser.

 

  1. Please paste the following script into the Expression window:

 

def FindLabel ([Identifier]):

    s = [Identifier]

    return s[20:]

 

  1. The [Name] field is the column that you want to label with.

 

  1. The [20:] in the script means choose the string start from 21st and to the last character of the cell value. If you want to start from another location, just change the “20” in the script.

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You should mark your answer as correct so that others with this same question can easily find it.