Results 1 to 8 of 8

Thread: Separate Family Name from First Name

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Separate Family Name from First Name

    Hey everyone,

    I need some simple string functions to locate the first space in a given string and separate the string before the space from the string after it.

    this is for separating a list of full names into 2 lists of first names and last names.

    Thanks in advance,

  2. #2
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: Separate Family Name from First Name

    why not make use of the split() function that splits a string up based on a certain delimiter (a space?)
    it returns an array indexed based on the delimiting character.
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  3. #3
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Separate Family Name from First Name

    Here is a sample
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim str As String, vName() As String
    5.   str = "Sam Spade"
    6.   vName() = Split(str)
    7.   MsgBox vName(1) & " " & vName(0)
    8. End Sub

    You might want to check Ubound(vname) to make sure that there aren't two last names, or a Jr, or Sr. If so, add it to the last name.

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Separate Family Name from First Name

    Splitting names is nearly impossible unless there are some strict rules about what the name can contain. Jr and Sr are one difficulty but you could also run into something like J. R. R. Tolkien.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Separate Family Name from First Name

    We inforce strict rules on data entry of names.

    LASTNAME, FIRSTNAME MIDDLENAME, SUFFIX

    such as: "SMITH, JOHN ROBERT, JR"

    We then can look for the commas to find the various parts we want to find.

    If all your names have only one space then you are lucky - if the names you have look anything like the names we have encountered - it's not an easy task...

    Personally - I would use INSTR to split a string into two pieces based on a space in the string. Using SPLIT with ARRAY's seems excessive to me.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Separate Family Name from First Name

    Splitting on the first space is ok as long as your names are entered correctly and in the correct order. Also, no "Oscar Mayer Del La Hoya, Jr." type naming.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Separate Family Name from First Name

    Quote Originally Posted by MartinLiss
    Splitting names is nearly impossible unless there are some strict rules about what the name can contain. Jr and Sr are one difficulty but you could also run into something like J. R. R. Tolkien.
    Very true. Parsing names is very difficult. There can be suffixes like Jr. Sr. There can be prefixes like Mr. Mrs. There can be middle names, there can be multiple last names.

    The format of the name can come Lastname, Firstname. It is very challenging.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    586

    Re: Separate Family Name from First Name

    Thanks a lot, I'll give it a try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width