0

I want to show labels in ArcMap on multiple lines. The label I have is written as: Caritas Lebanon Migrant Center, DRC, Handicap International, NRC, SCI. I want to show it in separate lines. e.g.:

Caritas Lebanon Migrant Center, DRC, 
Handicap International, NRC, SCI

Or:

Caritas Lebanon Migrant Center, DRC, 
Handicap International, NRC, 
SCI

Is that possible to do using an expression?

2 Answers 2

2

You could probably write a vb expression to replace every second comma, but I find it easier to work in python. Something like this would work:

def FindLabel([LABELFIELD]):
    labels = map(str.strip, [LABELFIELD].split(','))
    out = ''
    for i in xrange(0, len(labels), 2):
        if i + 1 < len(labels):
            out += '{}, {}\n'.format(labels[i], labels[i + 1]))
        else:
            out += labels[i]
    return out
2
  • Output comes like this: P,r,i,v,a,t,e, ,P,m, ...........
    – Mehmud
    Commented Nov 17, 2017 at 12:43
  • @Mehmud oops, sorry. Forgot to split the label field. I've edited the code.
    – jon_two
    Commented Nov 17, 2017 at 13:42
1

The ArcGIS Desktop help on Building label expressions explains how to use vbScript to:

Create stacked text. For example, this expression creates a label with the Name field and the two address fields all on separate lines:

"Name: " & [NAME] & vbCrLf& [ADDRESS_1] & vbCrLf& [ADDRESS_2]
2
  • This line of code worked for replacing comma(,) with new lines. FindLabel = replace([LABELFIELD], ", ", vbnewline) But I was looking for to replace every 2nd comma. Thanks for the help.as always.
    – Mehmud
    Commented Nov 17, 2017 at 9:34
  • That sounds like a slightly harder question so I think you should edit it to explain that the label is coming from only one field, and more precisely your scenario.
    – PolyGeo
    Commented Nov 17, 2017 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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