The fieldname only has three characters. I dont want to display zeros in the first and third values. example below.
010 = 1
100 = 10
01Y = 1Y
10Y = 10Y
I have figured out how to strip out zeros except for the second value.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Use Python as the parser, and check the Advanced box. Then just replace
yourFieldName with the name of the field you want to label.
def FindLabel([yourFieldName]): value = [yourFieldName] first = False third = False if value == "0": first = True if value == "0": third = True if first == True and third == False: return value[1:] elif first == False and third == True: return value[0:2] elif first == True and third == True: return value[1:2] else: return value
Just for good measure, here's a way to use python string methods. This would work with strings of variable length, though I know that wasn't a consideration in this case:
def FindLabel(value): if value.endswith("0"): value = value[:-1] # slice all but the last character if it's a 0 return value.lstrip("0") # take off any leading zeros
Here's a little more concise way of doing it. Basically convert it to a list and replace list and list with '' if the value is 0
def FindLabel([field]): value = [field] l_value = [x for x in value] # turns string to list no_zero_positions = [0,2] # where you don't want zeros for p in no_zero_positions: if l_value[p] == '0': l_value[p] = '' # Replace zero with empty string return ''.join(l_value) # list back to string