---
url: >-
  /statelake/scripting-reference/functions-and-procedures/string-functions/soundex-functions/soundex.md
---

# Soundex

**Soundex** is a function that creates the **Soundex** equivalent of the source string **AText**, using the **Soundex** algorithm.

The parameter **ALength** is the number of characters to use when generating the **Soundex** string. This value is accepted by either direct entry into the function, or via a variable.

The function is designed to encode words or names, and not entire sentences - although the **Soundex** value produced may be quite similar (see ‘a sentence’ below).

Case does not matter.

The function **SoundexInt** is similar, but the result is an integer. It can be reviewed here at [SoundexInt](/statelake/scripting-reference/functions-and-procedures/string-functions/soundex-functions/soundexint).

**Declaration**: Function Soundex(const AText : string; ALength : TSoundexLength) : string;

This code below illustrates that the algorithm is flawed - the **Soundex** of **Pierce** and **Perez** are exactly the same.

```pascal
procedure ScriptEvent (var Value : variant);
var
  sSound, sInput : string;
  aLen : TSoundexLength;
begin
  LogInfo('');
  sInput := 'Pumpkin';                    //Capuital 'P'
  sSound := Soundex(sInput, 10);
  LogInfo(sInput+' - '+sSound);
  sSound := Soundex(sInput, 5);
  LogInfo(sInput+' - '+sSound);

  sInput := 'pumpkin';                    //Lower case 'p'
  sSound := Soundex(sInput, 10);
  LogInfo(sInput+' - '+sSound);
  sSound := Soundex(sInput, 5);
  LogInfo(sInput+' - '+sSound);

  sInput := 'Perez';
  sSound := Soundex(sInput, 10);
  LogInfo(sInput+' - '+sSound);
  sSound := Soundex(sInput, 5);
  LogInfo(sInput+' - '+sSound);

  sInput := 'Pierce';
  sSound := Soundex(sInput, 10);
  LogInfo(sInput+' - '+sSound);
  sSound := Soundex(sInput, 5);
  LogInfo(sInput+' - '+sSound);

  LogInfo('');
  aLen := 8;                             //Entering aLength as a variable
  sInput := 'Statelake';
  sSound := Soundex(sInput, aLen);
  LogInfo(sInput+' - '+sSound);

  aLen := 20;
  sInput := 'a sentence';
  sSound := Soundex(sInput, aLen);
  LogInfo(sInput+' - '+sSound);

  LogInfo('');
  aLen := 6;
  sInput := 'a';
  LogInfo(sInput+' - '+Soundex(sInput, aLen));
  sInput := 'sentence';
  LogInfo(sInput+' - '+Soundex(sInput, aLen));
  LogInfo('');

end;
```
