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.
Solved! Go to Solution.
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
thank you
Hi Massimo, in the field calculator, choose the Python parser, and type:
!A![:-1]
thank you
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!
Haha! Dan takes the lead!
>>> ("{}"*(len(a)-1)).format(*a)
'1111'
enough...Or I will bring out numpy examples