Skip to content

Text nysiis encode

github-actions[bot] edited this page Aug 22, 2026 · 24 revisions

Nysiis.Encode

The NYSIIS code of one name.

public static string Encode(ReadOnlySpan<char> value)
public static string Encode(string value)

Parametersvalue is a single name. Non-letters in it are ignored rather than rejected, and case does not matter. The string overload forwards to the span one.

Returnsstring, an uppercase letter code of variable length — 1 to 11 characters over the corpus it is pinned to — or the empty string when value holds no letter.

ExceptionsArgumentNullException when value is null (the string overload only; a ReadOnlySpan<char> cannot be null). An empty string is accepted and encodes to the empty string.

Example — two name-specific opening rules, and the b/p distinction Soundex loses.

using Lodestar.Text.Phonetics;

string pf = Nysiis.Encode("Pfister");  // => FASTAR
string sch = Nysiis.Encode("Schmidt");  // => SNAD
string robert = Nysiis.Encode("Robert");  // => RABAD
string rupert = Nysiis.Encode("Rupert");  // => RAPAD

RemarksPfisterFASTAR is NYSIIS reading an initial PF as the f sound it is in a German-derived surname, which is the kind of rule it carries and the reason it is described as a name encoder rather than a word encoder.

Robert and Rupert landing on RABAD and RAPAD is the counterpart to Soundex.Encode giving both R163. Neither is wrong — they are answering different questions, and which one you want depends on whether a false match or a missed match is the expensive mistake.

Because the code is not truncated, its length tracks the length of the name. Two names of very different lengths will not collide here even when they start alike, which is most of where the precision comes from.

Applies to — net10.0, netstandard2.0.

See alsoNysiis, Soundex.Encode, the phonetics index.

Lodestar

Project

Clone this wiki locally