Tip

@Soundex In Lotus Script

Here' is a soundex function in LS-CODE.
The @Soundex-function does not work proper, when you have a non-alpha character
in your string:
Function charAt(s As String, i As Integer) As String
If i+1 > Len(s) Then
charAt = ""
Else
charAt = Right(Left(s, i+1), 1)
End If
End Function

Function toAlpha(s As String) As String
Dim i As Integer
Dim c As String
Dim chAlpha As String

chAlpha = ""
For i=0 To Len(s)
c = Ucase(charAt(s, i))
If c >= "A" And c <= "Z" Then
chAlpha = chAlpha + c
End If
Next
toAlpha = chAlpha
End Function

Function soundex(s As String) As String
Dim i As Integer, j As Integer
Dim chSoundexCode As String, chPrevSoundexCode As String, strResult As String,
chSwitch As String
Dim chAlphaName As String

chSoundexCode = "0"
chPrevSoundexCode = "0"
strResult = ""
chSwitch = ""

chAlphaName = toAlpha(s)

i = 0
j = 0
Do While i < Len(chAlphaName) And j < 4
chSwitch = charAt(chAlphaName, i)
If chSwitch = "R" Then
chSoundexCode = "6"
Else
If chSwitch = "M" Or chSwitch = "N" Then
chSoundexCode = "5"
Else
If chSwitch = "L" Then
chSoundexCode = "4"
Else
If chSwitch = "D" Or chSwitch = "T" Then
chSoundexCode = "3"
Else
If chSwitch = "C" Or chSwitch = "S" Or chSwitch = "K" Or chSwitch = "G" Or
chSwitch = "J" Or chSwitch = "Q" Or chSwitch = "X" Or chSwitch = "Z" Then
chSoundexCode = "2"
Else
If chSwitch = "B" Or chSwitch = "P" Or chSwitch = "F" Or chSwitch = "V" Then
chSoundexCode = "1"
End If
End If
End If
End If
End If
End If
If chSoundexCode > "0" Or j = 0 Then
If j = 0 Or chSoundexCode <> chPrevSoundexCode Then
strResult = strResult + chSoundexCode
j = j + 1
End If
End If
If j = 0 Then j = j + 1
chPrevSoundexCode = chSoundexCode
chSoundexCode = "0"
i = i + 1
Loop
For i = j To 4
strResult = strResult + "0"
Next
soundex = charAt(chAlphaName, 0) + Left(Right(strResult, 4), 3)
End Function

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.