soundex

Like soundexer, but with different parameters and return value.

@safe pure nothrow
char[]
soundex
(
scope const(char)[] str
,
return scope char[] buffer = null
)
out (result) { if (result !is null) { assert (result.length == 4, "Result must have length of 4"); assert (result[0] >= 'A' && result[0] <= 'Z', "The first character of " ~ " the result must be an upper character not " ~ result); foreach (char c; result[1 .. 4]) assert (c >= '0' && c <= '6', "the last three character of the" ~ " result must be number between 0 and 6 not " ~ result); } }

Parameters

str const(char)[]

String to convert to Soundex representation.

buffer char[]

Optional 4 char array to put the resulting Soundex characters into. If null, the return value buffer will be allocated on the heap.

Return Value

Type: char[]

The four character array with the Soundex result in it. Returns null if there is no Soundex representation for the string.

Examples

assert(soundex("Gauss") == "G200");
assert(soundex("Ghosh") == "G200");

assert(soundex("Robert") == "R163");
assert(soundex("Rupert") == "R163");

assert(soundex("0123^&^^**&^") == null);

See Also

Meta