Split a shared-name entry such as “John and Jane Smith” into separate people.
dotnet add package RecursiveAI.OneContactRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneContact.Names; var results = NameParsing.SplitMany( new[] { "John and Jane Smith" }); foreach (var result in results) { Console.WriteLine(result.Class); foreach (var person in result.Persons) Console.WriteLine(person.Canonical); }
Multiple John Smith Jane Smith
Unsettled input is returned as Unknown; inspect Class and Detail rather than treating every returned part as an identified person.
Unzip the example, then dotnet run.
Variations
Leave an ambiguous ampersand pair unresolved:
using RecursiveAI.OneContact.Names; var result = NameParsing.Split( "Johnson & Johnson"); Console.WriteLine(result.Class); Console.WriteLine(result.Persons.Count);
Unknown 0
Related recipes
The short answer
Use NameParsing.Split for one entry, or NameParsing.SplitMany for a collection of entries. Each result has a Class, a Persons collection and diagnostic Detail. A single entry can yield several people: the snippet at the top passes one entry through the batch API and receives John Smith and Jane Smith.
SplitMany does not take a single multi-person string as its batch argument. It takes an IEnumerable<string> and yields one NameParseResult per input entry. The distinction matters when importing a column: preserve the link between each source row and its result, even when that result contains several people.
How do I split multiple people’s names in C#?
Iterate the results, inspect each Class, and then decide whether to accept its Persons. The example prints the class before the names so a caller can see that the text was read as Multiple. In an import workflow, keep Unknown and Company entries for separate handling instead of silently dropping them.
The name rules recognize connectors, semicolons, line breaks and certain comma lists. A lone given name before a full name can share the following family name, as in the example. Titles also matter: in Mr & Mrs John Smith, a title-only part takes the whole name that follows. This is structured name interpretation, not merely cutting text at an ampersand.
The rules do not infer gender, origin or salutation. They preserve offsets into the original input; when two people share a written family name, their offsets can point to the same source text. Store the input if you need to show how the names were derived or allow someone to correct the reading.
How do I split a string with multiple delimiters in C#?
For known mechanical separators, string.Split is appropriate. Microsoft’s string-splitting guide covers arrays of separators and empty-entry handling. But a name field has semantic boundaries: a comma may mark family-first order, and a connector may belong inside one person’s family name.
Use the name parser when those distinctions matter. The documented example Maria Garcia y Lopez is one person, not two. Every proposed person must also read as a person when parsed alone, or the whole text becomes Unknown. A delimiter-only split loses that check and cannot decide when to share a surname.
How do I split full names into first and last names in C#?
First separate the people; then read each PersonName’s Given, Middle and Family parts as needed. Do not reverse those stages by taking the first word of the entire household entry as one person’s first name and the last word as their surname. That would discard the other person entirely.
The variation returns Unknown and no people for Johnson & Johnson. Two single words joined by a connector count as multiple people only when the first is a known given name. Leave that refusal intact instead of fabricating two contact records. Country and language hints can choose between readings left open by the text, but never overrule the text. Successful parsing is still a rules-based reading, not identity verification; keep a correction path for imports and forms.