2

I am trying to do a simple labelling exercise however bit confused how to on how to remove unwanted '0' values. I have field with road number displayed like: 0000647, 000652, 0000000236

I would like to have field road number without zeros: 647, 652, 236

1
  • 2
    If they're all numbers then you could int([field]) in the label expression. If they are alphanumeric (like 23a as 0023a) then change the parser to python and use [field].lstrip("0") to remove only leading 0's Commented Nov 24, 2014 at 2:20

2 Answers 2

1

I'm assuming that you are using ArcGIS 10.1 for Desktop or later, but this may also work with 10.0.

  1. Open up the Properties of your layer to the Labels tab.
  2. Make sure Label features in this layer is ticked on
  3. Change the Parser to Python.
  4. In the Expression area, if your field is called Name and your data is stored in a file geodatabase feature class, type:

    [Name].lstrip("0")

  5. Then click OK twice and you should see your result

enter image description here

6
  • It's dependent on the python parser for label expressions which may be available as far back as 9.3.1. The VB parser (default) has very few functions but the python parser has much greater scope for manipulation. Any chance you could include a graphic showing where to change the parser in the label dialog to python at step 3 PolyGeo, just for clarity. Commented Nov 24, 2014 at 3:08
  • I am using ARC10 in in expression box there in no paraser to Python. Can you supply expression for VBscript ?
    – piotrsocha
    Commented Nov 24, 2014 at 3:30
  • Sorry - I don't know the VBscript to do it. For ArcGIS Desktop questions be sure to always mention the version you are using in the body of your question.
    – PolyGeo
    Commented Nov 24, 2014 at 3:43
  • @PolyGeo, the VBscript is very limited, you have to replace 0's with spaces, ltrim the spaces and replace back again. It is possible but can be a little annoying trying to balance the brackets and parameters... python is sooo much easier! Commented Nov 24, 2014 at 4:28
  • @MichaelMiles-Stimson I did some quick unsuccessful experimenting with CInt and Clng as per stackoverflow.com/questions/22011506/… before giving up
    – PolyGeo
    Commented Nov 24, 2014 at 4:48
1

In the absence of a python parser your only real option is:

replace(ltrim(replace( [field] ,"0"," "))," ","0")

enter image description here

This assumes that you don't have any spaces inside your text, if you do then you need another two replaces:

replace(replace(ltrim(replace(replace( [SourceFC] ," ","~"),"0"," "))," ","0"),"~"," ")

Again, assuming that you have no ~ characters in your text. Substitute a different character if you need to, just remember what you replace with you will need to replace back again... chr(07) is a good one, no text will contain BEL ASCII character.

The way this works is the inner replace substitutes spaces for the 0's which are then removed before the numbers by ltrim, which only removes whitespace (spaces, tabs..) then any remaining spaces are replaced by 0's.

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.