I have a string
in the format "12345-0012-0123"
and I would like to change them all to be in the format of 12345-0012-123"
so that the last section after the dash is only three digits instead of four digit.
In all cases the last section after the dash will only have at most three real digits that I need to keep with a zero in front 0001, 0012, 0123...
Some strings that I will be editing are already in the correct format so a quick check to see if iI even need to perform correction would be better...
EDIT: Solved... !!
For any one interested this is the arc gis calculator code I am using that was modified from the answer provided by anirudh...
#Convert to three digit count
def FixCount(s):
length = len(s[s.rfind('-')+1:])
if length > 3:
return s.rstrip(s[s.rfind('-')+1:])+s[s.rfind('-')+2:]
else:
return s.rstrip(s[s.rfind('-')+1:])+s[s.rfind('-')+1:]
__esri_field_calculator_splitter__
FixCount(str( !input_field_id! ))