Hey!
I wish to use replace twice in the same field.
Attributes: >0980>Visy> GA: 8 must be labeled GA:8.
I use def FindLabel ([externid]):
return [externid] .replace ('0980>Visy', ''), but fails to add code so that even the last > disappear.
Anyone know how to write it?
Best regards,
Tomas
Solved! Go to Solution.
Without getting to regex, you can chain them with what you need.
.replace('>0980>Visy>', '').replace('>0980>Fran>', '')
If there are a lot, you can create a loop to iterate through all the variations from a list and replace them. Assuming there is a space there between the last > and GA:8,or you can find another way to parse out the part you want to replace.
for str in [str[0].split(' ')[0] for str in arcpy.da.SearchCursor(yourfc, [externid])]:
[exernid].replace(str, '')
or index it as Jayanta provided.
[externid].split('>')[-1]
Is there some that contains spaces (> 0980> Visy>) and others that do not (>0980>Visy) in your field? If that is the case, I'd suggest using
[externid].split('>')[-1].strip()
replace replaces the whatever string you put in the first parameter so you need to be explicit with what you want replaced.
.replace('>0980>Visy>', '')
Thanks for the reply!
I missed writing that Visy can consist of different names, it varies and can then be Fran instead of Visy.
Without getting to regex, you can chain them with what you need.
.replace('>0980>Visy>', '').replace('>0980>Fran>', '')
If there are a lot, you can create a loop to iterate through all the variations from a list and replace them. Assuming there is a space there between the last > and GA:8,or you can find another way to parse out the part you want to replace.
for str in [str[0].split(' ')[0] for str in arcpy.da.SearchCursor(yourfc, [externid])]:
[exernid].replace(str, '')
or index it as Jayanta provided.
[externid].split('>')[-1]
When I use .replace ('> 0980> Visy>', '') .replace ('> 0980> Fran>', '') then> 0980>Visy is included in the labeling but last> disappears.
Is there some that contains spaces (> 0980> Visy>) and others that do not (>0980>Visy) in your field? If that is the case, I'd suggest using
[externid].split('>')[-1].strip()
Thanks, it works!
Check if a similar script works
Parser: Python
(!FieldName!.split(' ',1)[1]).replace(' ','')