×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Split Full Name into Three Separate Items

Split Full Name into Three Separate Items

Split Full Name into Three Separate Items

(OP)
Hello...
I have a problem that I am hoping someone can help me with.

I have a field which contains the full name of an individual (i.e. "Public, John Q").

Is there a way to split this single field into three separate items that I can use to populate other variables.

I've used Split to get the last name and first name, but with the first name I end up with a firstname and middle initial. I need the middle initial separate as well.

Does anyone have a simple solution for this problem?
Thanks in advance.

RE: Split Full Name into Three Separate Items

Not reliably.

People from Spain/Portugal tend to have multiple middle names, and doing a simple Split() will get it wrong.

Chip H.

____________________________________________________________________
Donate to Katrina relief:
http://s1.amazon.com/paypage/PELYGQVJ8Q7IB/103-6821258-5919825
If you want to get the best response to a question, please read FAQ222-2244 first

RE: Split Full Name into Three Separate Items

(OP)
Thanks for your response.

RE: Split Full Name into Three Separate Items

(OP)
I found this someplace else and seems to work...
        Dim FullName As String
        FullName = "Public, John Q"

        UseRegularExpression(FullName)

    End Sub


    Private Sub UseRegularExpression(ByVal strName As String)
        Dim regExp As New Regex("([a-zA-Z]{1,})\,{1}\s{0,}([a-zA-Z]{1,})\s{0,}([a-zA-Z]{0,})")
        Dim matchGroups As GroupCollection = regExp.Match(strName).Groups

        ' Last name
        MsgBox(matchGroups(1).Value)
        ' First name
        MsgBox(matchGroups(2).Value)
        ' Middle initial (If any)
        MsgBox(matchGroups(3).Value)
    End Sub

RE: Split Full Name into Three Separate Items

How would that work with:

surname:
  O'Neill
  du Maurier
  van Beethoven
  or hyphenated

?

Additionally firstnames can be hyphenated or contain apostrophes and there may be more than one middle initial.

Your regular expression allows for an alpha surname of one or more characters a required comma, zero or more spaces followed by an alpha firstname of one or more characters followed by zero or more spaces and ending with zero or more alpha characters (no spaces allowed between middle initials if they exist)

As chip said, its not as easy as it may at first seem.  It can be done (to a great extent) with a regular expression, but it would need to be far more comprehensive than the one you posted.

Sorry to put a dampener on your solution.

RE: Split Full Name into Three Separate Items

CODE

dim FullName as String =  "Public, John Q"
dim FirstName as string = FullName.Split(",")(1).Split(" ")(0)

dim i as integer
dim MiddleName as string
for 1 = 1 to FullName.Split(",")(1).Split(" ").length-1
  MiddleName &= FullName.Split(",")(1).Split(" ")(0)
next

dim LastName as string = FullName.Split(",")(0)

It might take some tweeking, but it should be close. Provided you always have the format <LastName>,<FirstName> <MiddleName>. Lastname is always followed by a comma, firstname has no spaces but can be hyfinated, and middle name can be as long as you like with what every characters.

-Rick

VB.Net Forum forum796    forum855 ASP.NET Forum
    I believe in killer coding ninja monkeys.

RE: Split Full Name into Three Separate Items

I haven't had a chance to experiment with this yet, but I was thinking along the lines of using MeasureString to work out where in the TextBox the cursor is and then add this to the .Top and .Left of the TextBox, thus giving the .Top and .Left of the pop-up form.  I'll hopefully have a chance to play with this tonight.

RE: Split Full Name into Three Separate Items

Is that just a default reply you give to everyone now E&F?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

RE: Split Full Name into Three Separate Items

Sometimes, I experiment at the weekend

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close