I read various threads and theories regarding two string matching and convert matching value into Percentage.
there are some algorithms to calculate similarity like Lowenstein, but sometimes you need more then that
So, I written this code, and you will use it at your convenience
script matches two strings with word by word OR character by character
also match by case OR non case format
you can also find difference with (100 – Result)
If any suggestion then please write here
#include <Array.au3>
#include <File.au3>
#include <Math.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
$sStr01 = "My string Software v1.0"
$sStr02 = "My String Software v1.1"
ConsoleWrite("Standard: " & _StringMatchPercent($sStr01, $sStr02) & @CRLF) ; Return Standard: 95.65
ConsoleWrite("Case ON (Char lvl): " & _StringMatchPercent($sStr01, $sStr02, 1, 0) & @CRLF) ; Return "Case ON (Char lvl): 91.3"
ConsoleWrite("Case ON (word lvl): " & _StringMatchPercent($sStr01, $sStr02, 1, 1) & @CRLF) ; Return "Case ON (word lvl): 50"
ConsoleWrite("Case Off (Char lvl): " & _StringMatchPercent($sStr01, $sStr02, 0, 0) & @CRLF) ; Return "Case Off (Char lvl): 95.65"
ConsoleWrite("Case Off (word lvl): " & _StringMatchPercent($sStr01, $sStr02, 0, 1) & @CRLF) ; Return "Case Off (word lvl): 75"
Func _StringMatchPercent($FirstString = "", $SecondString = "", $iCaseSense = 0, $iMatchByWord = 0)
;~ ($iCaseSense : [0 = not case sensitive [, 1 = case sensitive]])
;~ $iSplitByWord : [0 = Match Character by Character [, 1 = Match word by Word]]
;~ ### Check/Set function header parameters
Local $sMatchBy = ($iMatchByWord = 0) ? "" : " "
Local $inCaseSense = ($iCaseSense = 0) ? 0 : 1
If $FirstString = "" Or $SecondString = "" Then Return "0"
Local $aFirstArray = StringSplit($FirstString, $sMatchBy, 2)
_ArraySort($aFirstArray) ; Sort Array to Ascending Order
;~ _ArrayDisplay($aFirstArray,"Show First Array")
Local $aSecondArray = StringSplit($SecondString, $sMatchBy, 2)
_ArraySort($aSecondArray) ; Sort Array to Ascending Order
;~ _ArrayDisplay($aSecondArray,"Show Second Array")
Local $inSL = 0 ;Second Level matching starting Point
Local $iMatchCount = 0
Local $sMatchArg = 0
; Now Matching Every First Array Element to Second Array Element
For $iFL = 0 To UBound($aFirstArray) - 1 ; $iPL = Represent First Array Position
For $iSL = $inSL To UBound($aSecondArray) - 1 ; $iSL = Second Array Position $inSL = Second Array Checking Start from
If StringCompare($aFirstArray[$iFL], $aSecondArray[$iSL], $inCaseSense) = 0 Then ; If Both Element Matched
$iMatchCount += 1 ; Match Count get +1
$inSL = $iSL + 1 ; Set New Starting Position for Second Array
ExitLoop ; Exit Loop for checking next element
EndIf
Next
Next
Local $iMax = _Max(UBound($aFirstArray), UBound($aSecondArray)) ; Finding Large Array for Calculation
Return Round((($iMatchCount <> 0) ? (($iMatchCount / $iMax) * 100) : 0), 2)
EndFunc