Splitting a person's name into forename and surname

前端 未结 16 1939
北海茫月
北海茫月 2020-12-05 10:46

ok so basically I am asking the question of their name I want this to be one input rather than Forename and Surname.

Now is there any way of splitting this name? and

相关标签:
16条回答
  • 2020-12-05 10:53
    name = "Thomas Winter"
    first, last = name.split()
    print("First = {first}".format(first=first))
    #First = Thomas
    print("Last = {last}".format(last=" ".join(last)))
    #Last = Winter
    
    0 讨论(0)
  • 2020-12-05 10:56

    Golden rule of data - don't aggregate too early - it is much easier to glue fields together than separate them. Most people also have a middle name which should be an optional field. Some people have a plethora of middle names. Some people only have one name, one word. Some cultures commonly have a dictionary of middle names, paying homage to the family tree back to the Golgafrincham Ark landing.

    You don't need a code solution here - you need a business rule.

    0 讨论(0)
  • 2020-12-05 10:56

    If you're trying to parse apart a human name in PHP, I recomment Keith Beckman's nameparse.php script.

    0 讨论(0)
  • 2020-12-05 10:56

    Splitting names is harder than it looks. Some names have two word last names; some people will enter a first, middle, and last name; some names have two work first names. The more reliable (or least unreliable) way to handle names is to always capture first and last name in separate fields. Of course this raises its own issues, like how to handle people with only one name, making sure it works for users that have a different ordering of name parts.

    Names are hard, handle with care.

    0 讨论(0)
  • 2020-12-05 10:58

    Like this:

    print name.split()[-1]
    
    0 讨论(0)
  • 2020-12-05 10:58

    It's definitely a more complicated task than it appears on the surface. I wrote up some of the challenges as well as my algorithm for solving it on my blog. Be sure to check out my Google Code project for it if you want the latest version in PHP:

    http://www.onlineaspect.com/2009/08/17/splitting-names/

    0 讨论(0)
提交回复
热议问题