Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Extract lastname from "lastname firstname"

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wrote some code at work to solve this problem, and I sound the solution quite pleasing and elegant to my eye
I'll drop the problem and see if anyone gets the same thing. (I'm running the data conversion on several thousand rows as I write)
In the database, names are stored as a single field NAME, and this is in the form "<lastname> <firstname>" (space separated). We want to try to separate it into two fields.
The firstname can be more than word, but we assume that anything after the last name is the firstname. The difficulty is finding the lastname. We assume that any last name that consists of several words is prefixed by one of: di, de, du, da, mac, van den, van der, van, de la.
Then the next name is part of the last name too.
Well, I enjoyed it, anyway. :roll:
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You might want to add "del", "della", "de los", "de las", and "mc". And who knows what else if we move past European languages.
[ June 03, 2003: Message edited by: Jim Yingst ]
 
SJ Adnams
Ranch Hand
Posts: 925
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(an aside)
our database holds european data. we have a 3 columns - firstname, lastname, fullname.
There are so many exceptions, and ways in how people like to be referred that we have to do this.
 
David Hibbs
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Simon Lee:
(an aside)
our database holds european data. we have a 3 columns - firstname, lastname, fullname.
There are so many exceptions, and ways in how people like to be referred that we have to do this.

This is why there are commercial packages especially for the purpose of data cleansing. A quick and dirty way is fine, but getting it right is another thing entirely.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic