Skip to content

Instantly share code, notes, and snippets.

@leadscloud
Created July 12, 2014 08:53
Show Gist options
  • Save leadscloud/ffb29f350dcef4f85c83 to your computer and use it in GitHub Desktop.
Save leadscloud/ffb29f350dcef4f85c83 to your computer and use it in GitHub Desktop.
格式化标题为首字母大写,特别符号除外
def sanitize_at_name(name, decode = False):
""" Sanitize achternaam, optionally decodes
to unicode string from AT input """
if decode:
name = unicode(name, 'iso-8859-15')
tussenvoegsels = [
"af",
"aan",
"bij",
"de", "den", "der", "d",
"het", "t",
"in",
"onder",
"op",
"over",
"'s",
"'t",
"te", "ten", "ter",
"tot",
"uit", "uijt",
"van", "vanden",
"ver",
"voor",
]
return " ".join([word.title() if word.lower() not in tussenvoegsels
else word.lower() for word in name.split()])
print(sanitize_at_name("the cat van walked de down the road."))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment