Text 0.4.0 soundex encode - CyrilB1531/lodestar GitHub Wiki
Lodestar.Text 0.4.0. This page is frozen at that release. Read the current documentation for what
mainsays now. A link to a decision or a migration page followsmain, and leaves the archive.
The 4-character Soundex code of one word.
public static string Encode(ReadOnlySpan<char> value)
public static string Encode(string value)Parameters — value is a single word. Non-letters in it are ignored rather than rejected, and
case does not matter. The string overload forwards to the span one, so passing a string
allocates nothing extra.
Returns — string: an uppercase letter followed by three digits, always exactly four
characters — or the empty string when value holds no letter at all.
Exceptions — ArgumentNullException 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 — a collision, and a word with too few consonants to fill the code.
using Lodestar.Text.Phonetics;
string robert = Soundex.Encode("Robert"); // => R163
string rupert = Soundex.Encode("Rupert"); // => R163
string padded = Soundex.Encode("Lee"); // => L000Remarks — L000 is the padding rule doing its work: Lee has one codeable consonant and the
code is still four characters wide, because a fixed width is what lets Soundex be an index key.
A null word is refused, the same rule the stemmers in
Lodestar.Text.Stemming apply — decision 0042
records why the two used to disagree and why refusing won.
The two overloads are the same algorithm; the span one exists so a word already sliced out of a larger buffer can be encoded without copying it.
Applies to — net10.0, netstandard2.0.
See also — Soundex, Nysiis.Encode,
the phonetics index.