I have to copy a field (text) into another field (text) except the last letter/number.
For istance:
in field "A" with attribute "1111A"
I want to get just 1111 in field "B"
how can I do it?
thank you in advance.
Hi Massimo, in the field calculator, choose the Python parser, and type:
!A![:-1]
"1111A" is the value
In python for example
>>> a = "1111A"
>>> b = a[:-1]
>>> b
'1111'
>>>
so in the field calculator, you would setup a new field probably text if you can't guarantee all the slicing will be numeric, then use the field calculator syntax with the python parser selected a
oldfield[:-1]
the : means everything up to and -1 means the last one (counting backward from the end. There is a whole section on field calculations in the online help files... ie from the 10.3 help Fundamentals of field calculations—Help | ArcGIS for Desktop
In your field calculator !fieldName![:-1]
thank you
Haha! So funny that we all posted the right answer at the same time
Nice one Sephe!!! Good to know...
I got a longer one though
Left( ["FieldName"], Len( ["FieldName"] ) - 1 )
It would be fun to have a competition to see who could write the longest piece of code to simply strip one character off the end of a field!
"".join([a for i in range(len(a)-1)])
where a = !yourfieldname!
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.