String similarity functions?

Results 1 to 6 of 6

Thread: String similarity functions?

  1. #1
    Jim d. Guest

    Default String similarity functions?

    Hello All,<BR><BR>I&#039m looking for a function that would allow me to measure the *similarity* between two strings (rather than a straight strcmp). I&#039ve seen this for Perl & PHP, but haven&#039t seen an ASP or VBScript equivalent.<BR><BR>Any ideas? --Jim<BR>

  2. #2
    Siboo Guest

    Default RE: String similarity functions?

    Jim,<BR>There are a couple ways to do this.<BR>One is use strcomp(s1,s2,var) Where s1 and s2 are strings to compare and var is a flag that sets it to be case sensitive or insensitive. var = 0 or absent = case significant. 1 is insignificant case. Note that var=0 is same as s1 = s2 test.<BR>The other method is to implement your own function based upon ascii comparison of each letter of the string. It would be a bit lengthy but would work. You would have to loop through the strings, for the lenght of shorter string and compare each letter at N position. (n is loop variable). Just use Asc(char) to return numeric value of the character. At each test , return -1, 0 , or 1 for less than, equal or greater than. Note that on equal, the loop will continue.<BR><BR>Hope this helps.

  3. #3
    Join Date
    Dec 1969

    Default RE: String similarity functions?

    You can also look into "Regular Expressions". With a lot of study and a bit of work, you could implement something that will almost surely do what you want.<BR><BR>

  4. #4
    Jim d. Guest

    Default That may not work.

    Siboo,<BR><BR>Thanks for the reply, but I don&#039t think this will help for my particular problem.<BR><BR>Consider the reference string:<BR>"Jim&#039s house"<BR><BR>To these strings:<BR> 1)"jim&#039s house" &#060;-- case difference<BR> 2)"Jims house" &#060;-- no apostrophe<BR> 3)"Jim&#039s hose" &#060;-- fat-fingered entry<BR><BR>All of these strings are *similar*, but only 1) would be matched with a string compare. The algortithn you suggest would fail for 2) and 3) because checking all the tests after a particular index would fail.<BR><BR>Something "fuzzy", like what you get with the perl and php similar() function would be ideal here.<BR><BR>Anyway, thanks for the suggestion. It may come in handy for a later scenario.

  5. #5
    Jim d. Guest

    Default RE: String similarity functions?

    &nbsp;<BR>Bill,<BR><BR>Yeah. I was hoping for a silver bullet and avoid regular expressions, but I don&#039t think this will be the case. Thanks for the reply. --Jim

  6. #6
    Siboo Guest

    Default RE: That may not work.

    Ahh ok I see where you are going with this. Hmm that is a good question. I will keep my eye out and let you know if I can find any references.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts