Skip to content

Instantly share code, notes, and snippets.

@thanhleviet
Created July 6, 2012 07:42
Show Gist options
  • Save thanhleviet/3058735 to your computer and use it in GitHub Desktop.
Save thanhleviet/3058735 to your computer and use it in GitHub Desktop.
Field calculator to search and replace string field.
def SearchAndReplace(field):
global giatri
if field.find("Huyện") <> -1:
giatri= field.replace("Huyện","H.")
elif field.find("Huyên") <> -1:
giatri =field.replace("Huyên","H.")
elif field.find("Thị Xã") <> -1:
giatri= field.replace("Thị Xã","TX.")
elif field.find("Thị xã") <> -1:
giatri= field.replace("Thị xã","TX.")
elif field.find("Thị Trấn") <> -1:
giatri= field.replace("Thị trấn","TT.")
elif field.find("Thành Phố") <> -1:
giatri= field.replace("Thành Phố","TP.")
elif field.find("Thành phố") <> -1:
giatri= field.replace("Thành phố","TP.")
elif field.find("Quận") <> -1:
giatri= field.replace("Quận","Q.")
else:
giatri = field
return giatri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment