Splitting a person's name into forename and surname

前端 未结 16 1941
北海茫月
北海茫月 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 11:16

    I would specify a standard format (some forms use them), such as "Please write your name in First name, Surname form".

    It makes it easier for you, as names don't usually contain a comma. It also verifies that your users actually enter both first name and surname.

    0 讨论(0)
  • 2020-12-05 11:19

    The problem with trying to split the names from a single input is that you won't get the full surname for people with spaces in their surname, and I don't believe you'll be able to write code to manage that completely.

    I would recommend that you ask for the names separately if it is at all possible.

    0 讨论(0)
  • 2020-12-05 11:19

    You can use str.find() for this.

    x=input("enter your name ")
    l=x.find(" ")
    print("your first name is",x[:l])
    print("your last name is",x[l:])
    
    0 讨论(0)
  • 2020-12-05 11:20

    This is a pretty old issue but I found it searching around for a solution to parsing out pieces from a globbed together name.

    http://code.google.com/p/python-nameparser/

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