Removing Zeros From a Field

10637
7
03-14-2019 01:17 PM
MichelleCouden
Occasional Contributor

Anyone remember how to remove zeros from in front of a number in a field. For example, I have 00012. I want 12.

I forgot the formula in the field calculator. 

7 Replies
Robert_LeClair
Esri Notable Contributor

I found this bit of code on the Microsoft Community page that should work in the Field Calculator using VBScript:

Assuming there is no space character in the data:

Replace( LTRIM(Replace( fieldName, "0", " ")), " ", "0")

 

The part in bold replace all zeros by spaces, and then, left-trim that result, ie, remove starting spaces. The external Replace replaces the spaces left in the string to their initial 0 character.

JoeBorgione
MVP Emeritus

In python you can use:

!field_name!.lstrip('0')

That'll strip off any leading zeros:

That should just about do it....
MatthewDuffy
Occasional Contributor II

Thank you Joe Borgione, this is helpful and I remain grateful for your input

0 Kudos
MatthewDuffy
Occasional Contributor II

Used to be that we could simply multiply the text as a number by 1

so

000012 x 1 = 12

Trying to find out what this might look like today from within ArcPro is up to you

JoeBorgione
MVP Emeritus

This thread popped up in my activity log today. You can do the same calculation in pro as I described above or use the int() function :

JoeBorgione_0-1610558667758.png

 

JoeBorgione_1-1610558737351.png

 I guess the int() function would have worked originally too....

That should just about do it....
DavidWheelock2
Occasional Contributor II

Is there an Arcade solution? 

0 Kudos
JoeBorgione
MVP Emeritus

Don't know offhand:  check here and take a look...

That should just about do it....
0 Kudos