Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Soundex - Determine the phonetic code of a word
[ All Languages » VB »  String]

Total Hit ( 1955)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 



Click here to copy the following block
' The Soundex code of an alphabetical string
'
' you can use Soundex code for phonetic searches
' Beware: this isn't bullet-proof!
'
' UPDATE: this version corrects a bug in the original routine
'     thanks to Edward Wittke for spotting the mistake

Function Soundex(ByVal word As String) As String
  Dim result As String
  Dim i As Long, acode As Integer
  Dim dcode As Integer, oldCode As Integer
  
  ' soundex is case-insensitive
  word = UCase$(word)
  ' the first letter is copied in the result
  Soundex = Left$(word, 1)
  oldCode = Asc(Mid$("01230120022455012623010202", Asc(word) - 64))
  
  For i = 2 To Len(word)
    acode = Asc(Mid$(word, i, 1)) - 64
    ' discard non-alphabetic chars
    If acode >= 1 And acode <= 26 Then
      ' convert to a digit
      dcode = Asc(Mid$("01230120022455012623010202", acode, 1))
      ' don't insert repeated digits
      If dcode <> 48 And dcode <> oldCode Then
        Soundex = Soundex & Chr$(dcode)
        If Len(Soundex) = 4 Then Exit For
      End If
      oldCode = dcode
    End If
  Next
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.