|
-
Nov 5th, 2005, 03:26 PM
#1
Thread Starter
Fanatic Member
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,
-
Nov 5th, 2005, 03:30 PM
#2
Fanatic Member
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.
-
Nov 5th, 2005, 03:44 PM
#3
Re: Separate Family Name from First Name
Here is a sample
VB Code:
Option Explicit
Private Sub Form_Load()
Dim str As String, vName() As String
str = "Sam Spade"
vName() = Split(str)
MsgBox vName(1) & " " & vName(0)
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.
-
Nov 5th, 2005, 04:15 PM
#4
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.
-
Nov 5th, 2005, 04:25 PM
#5
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.
-
Nov 5th, 2005, 05:36 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Nov 5th, 2005, 05:49 PM
#7
Hyperactive Member
Re: Separate Family Name from First Name
 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.
-
Nov 6th, 2005, 01:27 PM
#8
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|