def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] + "-" + Split[1] + "- \n" + Split[2] return expression else: return Split[0] Likewise mine labelled all the samples. It will only work if there are 3 or less cities names in the name field.I like yours Sol, except it splits single names in half, I think those ones would be fine on one line, but I guess its not my call.
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] + "-" + Split[1] + "- \n" + Split[2] return expression else: return Split[0]
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" Split[1] elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression
Whoops left off a + sign def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] elif len(Split) == 3: expression = Split[0] +"-" + Split[1] + "- \n" + Split[2] return expression GIve that a shot.
def FindLabel ( [Name] ): Split = [Name].split(",") Split = Split[0] #drops everything after comma Split = Split.split("-") #splits by the hyphen if len(Split) == 2: expression = Split[0] + "- \n" + Split[1] return expression elif len(Split) == 3: expression = Split[0] + "-" + Split[1] + "- \n" + Split[2] return expression
It worked for me with the sample data you sent. Function FindLabel ([NAME]) pos = instr([NAME],"," ) lab = Left([NAME], pos - 1) leng = len(lab) half = Int(leng/2) first = left(lab,half) digits = leng-half nex = right(lab,digits) FindLabel = first & vbnewline & nex End FunctionThanks, Sol
Function FindLabel ([NAME]) pos = instr([NAME],"," ) lab = Left([NAME], pos - 1) leng = len(lab) half = Int(leng/2) first = left(lab,half) digits = leng-half nex = right(lab,digits) FindLabel = first & vbnewline & nex End Function
Yeah, I agree splitting the text in half like that is not really nice, but the OP said that it didn't matter so I didn't make it more complicated. Plus I'm racing against you to figure it out. lol 🙂 Plus I have to leave work now...
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.