Subj : Re: Detecting if 2 names are probably the same To : comp.lang.smalltalk,comp.programming From : Chris McDonald Date : Wed Jul 20 2005 11:30 pm "Rob Thorpe" writes: >Yes it would. But after you've figured that out it would be useful to >be able to detect things that are caused by minor typos and >mispellings, since they would also be a problem. Minor typos detected by the appended code. ______________________________________________________________________________ Dr Chris McDonald E: chris@csse.uwa.edu.au Computer Science & Software Engineering W: http://www.csse.uwa.edu.au/~chris The University of Western Australia, M002 T: +618 6488 2533 Crawley, Western Australia, 6009 F: +618 6488 1089 #define streq(s,t) (strcmp(s,t)==0) enum howbad {EXACT,TRANSPOSE,MISMATCH,EXTRACHAR,MISSINGCHAR,HOPELESS} ; enum howbad similar(s,t) char *s, *t; { while(*s++ == *t) if(!*t++) return(EXACT); /* exact match */ if(*--s) { if(*t) { if(s[1] && t[1] && *s == t[1] && *t == s[1] && streq(s+2,t+2)) return(TRANSPOSE); /* transposition */ if(streq(s+1,t+1)) return(MISMATCH); /* one char mismatch */ } if(streq(s+1,t)) return(EXTRACHAR); /* extra character */ } if(*t && streq(s,t+1)) return(MISSINGCHAR); /* missing character */ return(HOPELESS); /* hopeless */ } .