@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

Dig Deeper

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close