Skip to content

Human name parser based on JavaScrip-Name-Parser by Josh Fraser.

License

Notifications You must be signed in to change notification settings

nachocove/CSharp-Name-Parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSharp-Name-Parser

C# library to split names into their respective components (first, last, etc)

Usage:

var parsed = NameParse.parse("Mr. Chales P. Wooten, III");

Results:

parsed { 
    salutation: "Mr.", 
    firstName: "Charles", 
    initials: "P", 
    lastName: "Wooten", 
    suffix: "III" 
}

The algorithm:

We start by splitting the full name into separate words. We then do a dictionary lookup on the first and last words to see if they are a common prefix or suffix. Next, we take the middle portion of the string (everything minus the prefix & suffix) and look at everything except the last word of that string. We then loop through each of those words concatenating them together to make up the first name. While we’re doing that, we watch for any indication of a compound last name. It turns out that almost every compound last name starts with 1 of 15 prefixes (Von, Van, Vere, etc). If we see one of those prefixes, we break out of the first name loop and move on to concatenating the last name. We handle the capitalization issue by checking for camel-case before uppercasing the first letter of each word and lowercasing everything else. I wrote special cases for periods and dashes. We also have a couple other special cases, like ignoring words in parentheses all-together.

Credits & license:

About

Human name parser based on JavaScrip-Name-Parser by Josh Fraser.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%