Select to view content in your preferred language

Remove numbers from Labels

4097
10
Jump to solution
09-08-2014 03:02 AM
DrMar
by
Deactivated User

Hi,

I have labels that contain letters,symbols and numbers : (12/34-5) Name

I would like to remove (12/34-5) and leave Name only

Any suggestions?

0 Kudos
1 Solution

Accepted Solutions
RiyasDeen
Frequent Contributor

Hi Mar,

You can use a label expression. Go to label tab in layer properties and select label expression. use below label expression to create your label (please be mindful of line intend)

import re

def FindLabel ( [CODETEMPS]  ):

p = re.search('(?=\()(.*?)(?=\))', [CODETEMPS])

if p is None:

  return [CODETEMPS]

else:

  return p.group(0).replace('(','')

Below screenshot of label created using above expression.

Untitled.png

View solution in original post

0 Kudos
10 Replies
AnthonyGiles
Honored Contributor

If you are using the filed calculator and if your numbers are always the same length (in this case 10 characters (including the space before the Name)), you could use:

Right([Field],length([Field])-10)

or you could split the field on the space and grab the second part:

Split([Field], " ")(1)

If you would prefer to use python as the parser then there is a good example here:

Field Calculator: I just want the third word | SoCalGIS.org

0 Kudos
DrMar
by
Deactivated User

Sorry my mistake,

format is 123/45-67 (Name) and not all have that format.

Some of them are just Name without numbers

So I have to lose numbers and brackets

0 Kudos
GünterDörffel
Frequent Contributor

Hey - best would be to see all the versions of texts in your data. And I assume it is about ArcGIS for Desktop-Labeling? Your solution would look something like this: Take the whole String and filter out the crap. Would be easiest if all Names are in brackets - assuming they are not, try this as a python Advanced labeling expression - changing the [fieldname] in the brackets with your real fieldname:

def FindLabel([theName]):

    #get the text in the field

    txt = [theName]

    # if txt has a blank in it (which means it has the date), get rid of it

    if " " in txt:

        txt=txt.split(' ')[1]

    #now do the same with the leading bracket - non-existance is no problem this way

    if "(" in txt:

        txt=txt.split('(')[1]

    #and the ending bracket  - non-existance is no problem this way

    if ")" in txt:

        txt=txt.split(')')[0]

    return txt

0 Kudos
DrMar
by
Deactivated User

There are Names with 2 words so they have space in it.

I was thinking more like this:

replace ) with ""

split at )

but I need code

0 Kudos
GünterDörffel
Frequent Contributor

Can you send a table/Feature class with your content – I’ll write the code for you …

Von: Dr Mar

Gesendet: Monday, September 08, 2014 2:42 PM

An: Dörffel Günter

Betreff: Re: - Remove numbers from Labels

GeoNet <http://jiveon.jivesoftware.com/wf/click?upn=Dg1s4x8le7Lmxv8KWGaqo8h7SGfRSMkw-2FpvHGF9-2FW3rK-2Bvs1kL9-2FnG6jjf2NZhrLDz0M-2BrY-2By9IaziQEKVk3Hg-3D-3D_jo6fQuMO5tmmZMbKZISRTYtLRFL6G-2BWYRcHos6w-2Fs9ZjB1NyMC1mkFLIChdVNwcL-2FLcuOruNkNng-2FPgOoQ3P5jjj1yGPI9aV1LJnEBtYv6F7Kkn26CdyXuxYH5Fsbi-2FZWUTc3f0Z6z-2FFgealH1gABh9lJshqwlvE9Y6xXxu5vUI5oDlncYxscwUWk6uX6Pv7uuwOXErxHqPnwbTxduSNJCJT4y-2FVjFLjeGnjXmVGoNlDQl2U5nsOxVnihdNLgL2uSYKubMD63L6R7ZjV0cPGlrRO6wPwlfshCX3bYZLc-2B-2Fu6nTpmP16-2F51szPmNmL74XyxWY12M4pI278-2F8Ry7OXYQ-3D-3D>

Remove numbers from Labels

reply from Dr Mar<http://jiveon.jivesoftware.com/wf/click?upn=Dg1s4x8le7Lmxv8KWGaqo7A4BXwO9PY1WvQ5cXCtK4-2F9u3-2FEibE7Tt9Fk4AGtA63Rv7IcOjSP-2BzQWI60cQDFFq-2BB0NH8qz0eStWSjjUfp14-3D_jo6fQuMO5tmmZMbKZISRTYtLRFL6G-2BWYRcHos6w-2Fs9ZjB1NyMC1mkFLIChdVNwcL-2FLcuOruNkNng-2FPgOoQ3P5jjj1yGPI9aV1LJnEBtYv6F7Kkn26CdyXuxYH5Fsbi-2FZWUTc3f0Z6z-2FFgealH1gABk6FibgtJKKXOOdXKsiDwvmbP-2FLa-2Bs69Xyo3JKyin1rbJkY8F4E9OGvMnW8WLweJaDxv8gPZ0yM46HOV-2FvUB5id0knn3MPiK41iC4GF5gcBh4a17skIDcUDK-2FKBdtg-2FoK-2FxUa9uIGYnvZypbl4tAmeqjqVo2d-2FUyOeSDTJInpCzeATzwhwM3aomm3udkaYXzbw-3D-3D> in Managing Data - View the full discussion<http://jiveon.jivesoftware.com/wf/click?upn=Dg1s4x8le7Lmxv8KWGaqo0VQjeJBYpG9HGC8QZBT-2FEyI1eyJe-2Bi9EKx73W52pIjeAE8mTB5dX41nduq8xENU-2Fur2ImyCmcjJ6Wf4YQoywEo-3D_jo6fQuMO5tmmZMbKZISRTYtLRFL6G-2BWYRcHos6w-2Fs9ZjB1NyMC1mkFLIChdVNwcL-2FLcuOruNkNng-2FPgOoQ3P5jjj1yGPI9aV1LJnEBtYv6F7Kkn26CdyXuxYH5Fsbi-2FZWUTc3f0Z6z-2FFgealH1gABpOD000HuA62ja42shrIpPQ3L3ucOib0r4rhfXYD74OcKQ-2BHwqGBZewBQOuIGEbiBTRhBPFg6lPTVp5hWMnJC49dvSbQhYPXsBs3Rbge8ViRdS4Ihp0OBcaR-2F3UN7DMbOvTbPuT12eoNxZLYb4hJ0CndwNrQAcHekRvqe6qM4A7AKVX8nbDZ-2F8muxJWOOKO8xw-3D-3D>

0 Kudos
DrMar
by
Deactivated User

Here is a "dummy" table.

Names_full is current status and Names_split is how it should be

0 Kudos
GünterDörffel
Frequent Contributor

Here are two versions

  • One plain what you asked for
  • Second with a formated first character ... check the code ..

Just load as Advanced Python labeling expressions ...

Is that it?

regards
Guenter

0 Kudos
TimothyHales
Esri Notable Contributor

I've moved your post into the Managing Data space. You will get a much better answer here as the GeoNet Help is intended for community help and feedback. You can see more on the community structure, and what topics are under each space from the following documents:

GeoNet Community Structure

ArcGIS Discussion Forums Migration Strategy

Thanks!

Timothy

0 Kudos
RiyasDeen
Frequent Contributor

Hi Mar,

You can use a label expression. Go to label tab in layer properties and select label expression. use below label expression to create your label (please be mindful of line intend)

import re

def FindLabel ( [CODETEMPS]  ):

p = re.search('(?=\()(.*?)(?=\))', [CODETEMPS])

if p is None:

  return [CODETEMPS]

else:

  return p.group(0).replace('(','')

Below screenshot of label created using above expression.

Untitled.png

0 Kudos