Skip to content

Commit ef17fc6

Browse files
authored
Merge pull request #25 from JonCGroberg/patch-1
Enhance README.md with documentation for Multiple Names Parsing, Improved Nickname Handling, and Installation
2 parents 6e529cf + b846f14 commit ef17fc6

File tree

1 file changed

+71
-13
lines changed

1 file changed

+71
-13
lines changed

README.md

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,84 @@
11
# NameParserSharp
22

3-
Based upon [nameparser 0.36](https://pypi.python.org/pypi/nameparser), NameParserSharp is a C# library that parses a human name into constituent fields `Title`, `First`, `Middle`, `Last`, `Suffix`, and `Nickname` from the `HumanName` class. For example:
3+
Based upon python [nameparser 0.36](https://pypi.python.org/pypi/nameparser), NameParserSharp is a C# library that parses a human name into constituent fields `Title`, `First`, `Middle`, `Last`, `Suffix`, and `Nickname` from the `HumanName` class. NameParserSharp implements the functionality of the Python project on which it is based in a C# idiomatic way. It also,
4+
* eliminates nearly all regular expressions for efficiency
5+
* adds unit tests
6+
* improves nickname handling to expand delimiters: `John (Jack) Torrence` == `John 'Jack' Torrence` == `John "Jack" Torrence`
7+
* parses out multiple names from a single string as you might expect, as in `mr john and mrs jane doe`
8+
9+
10+
## Installation
411

12+
### Using NuGet Package Manager
13+
```powershell
14+
Install-Package NameParserSharp
15+
```
16+
### Using .NET CLI
17+
```bash
18+
dotnet add package NameParserSharp
19+
```
20+
## Quick Start
21+
### Basic Usage
22+
Start parsing names by creating an instance of the HumanName class with the full name string. Access the parsed components through the provided properties.
523
```c#
624
var jfk = new HumanName("president john 'jack' f kennedy");
725

8-
// person.Title == "president"
9-
// person.First == "john"
10-
// person.Middle == "f"
11-
// person.Last == "kennedy"
12-
// person.Nickname == "jack"
26+
// Accessing name components
27+
Console.WriteLine(jfk.Title); // Output: president
28+
Console.WriteLine(jfk.First); // Output: john
29+
Console.WriteLine(jfk.Middle); // Output: f
30+
Console.WriteLine(jfk.Last); // Output: kennedy
31+
Console.WriteLine(jfk.Nickname); // Output: jack
1332
33+
// Parsing an alternative format
1434
var jfk_alt = new HumanName("kennedy, president john (jack) f");
15-
1635
Assert.IsTrue(jfk == jfk_alt);
1736
```
37+
### Parsing Multiple Names
38+
Enable the parsing of multiple names within a single string by setting the ParseMultipleNames flag to true. This is useful for handling inputs like "John D. and Catherine T. MacArthur."
39+
```c#
40+
// Enable parsing of multiple names
41+
HumanName.ParseMultipleNames = true;
42+
43+
// Example full name containing two individuals
44+
string fullName = "John D. and Catherine T. MacArthur";
45+
46+
// Instantiate the HumanName class with the full name
47+
HumanName name = new HumanName(fullName);
48+
49+
// Display primary name components
50+
Console.WriteLine("Primary Name:");
51+
Console.WriteLine($" First Name: {name.First}");
52+
Console.WriteLine($" Middle Name: {name.Middle}");
53+
Console.WriteLine($" Last Name: {name.Last}");
54+
Console.WriteLine($" Suffix: {name.Suffix}");
55+
Console.WriteLine($" Nickname: {name.Nickname}");
56+
Console.WriteLine($" Title: {name.Title}");
57+
Console.WriteLine();
58+
59+
// Check and display additional name components if present
60+
if (name.AdditionalName != null)
61+
{
62+
Console.WriteLine("Additional Name:");
63+
Console.WriteLine($" First Name: {name.AdditionalName.First}");
64+
Console.WriteLine($" Middle Name: {name.AdditionalName.Middle}");
65+
Console.WriteLine($" Last Name: {name.AdditionalName.Last}");
66+
Console.WriteLine($" Suffix: {name.AdditionalName.Suffix}");
67+
Console.WriteLine($" Nickname: {name.AdditionalName.Nickname}");
68+
Console.WriteLine($" Title: {name.AdditionalName.Title}");
69+
}
70+
```
71+
### Normalization
72+
Ensure consistency by normalizing and capitalizing name components using the `Normalize` method. This method formats each part of the name appropriately.
73+
```c#
74+
var rawName = "juan de garcia";
75+
var name = new HumanName(rawName);
76+
77+
// Normalize the name
78+
name.Normalize();
79+
80+
Console.WriteLine(name.FullName); // Output: Juan de Garcia
81+
```
1882

19-
NameParserSharp implements the functionality of the Python project on which it is based in a C# idiomatic way. It also,
2083

21-
* eliminates nearly all regular expressions for efficiency
22-
* adds unit tests
23-
* improves nickname handling to expand delimiters: `John (Jack) Torrence` == `John 'Jack' Torrence` == `John "Jack" Torrence`
24-
* parses out multiple names from a single string as you might expect, as in `mr john and mrs jane doe`
2584

26-
NameParserSharp is available as a NuGet package: `Install-Package NameParserSharp`

0 commit comments

Comments
 (0)