n 8/9/07, Robert Klemme <shortcutter / googlemail.com> wrote:
> 2007/8/9, Tomislav Kralj <rex14012001 / yahoo.com>:
> > A part of my program is to compare two strings and as a result I have to
> > get a number (range:0-1) which represents a similarity beetwen those two
> > strings.
>
> There is no general answer to your question.  It depends on what you
> want to do with the result. There must be some requirements or at
> least more information about the nature of your problem.  There is no
> general definition of the term "similarity" for text strings - it
> really depends on the application case.
>
The problem description made me think of bioinformatics - especially
comparing genetic distances.  You can measure similarity as the number
of changes needed to transform one string into another.   If that
sounds like the type of similarity you need, look up Levenshtein
Distance:  http://en.wikipedia.org/wiki/Levenshtein_distance

In fact, there was a Ruby Quiz dealing with a similar problem:  Word
Chains - http://www.rubyquiz.com/quiz44.html.  The difference was that
the quiz only allowed changes that resulted in valid dictionary words.

-Adam