15,921,028 members
4.00/5 (1 vote)
See more:
i want to compare two strings and calculate the percentage of difference between them. This could have been easier for two strings of same length. But what if the length is different? For eg :

hello my name is amit and i like to help everybody

hi my name is amit and i would like to help every coder

I want to calculate the percentage of difference between them

A simple logic would be to compare each word in first sentence with same position word of different sentence. But in this case the length is different. So how do i proceed?

Any help would be appreciated.
Posted

## Solution 2

Basically you need to decide on a string metric and then calculate the difference for your strings. There are many possible metrics, so it depends on how you want to define degrees of "different."

See here for start[^]. As mentioned, the Levenshtein metric is probably the most common.

## Solution 1

See here[^].

If you can get an array back (containing all the differences as is provided by the author here), you can calculate the percentage by calculating the differences versus the original string lengths.

v2