How do I find the match % of two texts?

Hello inventors !
How do I find the match % of two texts ?
I mean -


Text1 = a
Text2 = a
Match% = 100%
Text1 = ab
Text2 = ac
Match% = 50%
Text1 = qwerty
Text2 = asdfgh
Match% = 0%



Thanks !

I think the easiest way is to use a loop and test each character in Text1 to see if there is a matching character in Text2. Increment the record of matches.

Text1 = abcdefg
Text2 = zcdehw

Number of chars in Text1 = 7
Number of matching chars in Text2 = 3

7/100 = 0.07
3/0.07 = 43% (rounded up)

Text1 = abc
Text2 = aaa
match% = ? %

Text1 = abc
Text2 = abbccd
match% = ? %

Also: Do the texts have to be the same length?

The original post is ambiguous.

Do matches have to be at the same location?

No. It can be of different length.

Then answer my other questions:

In other words, which matching algorithm should be used here?