Hallo,
Ich benötige einen Vergleich zweier Strings und die Match Genauigkeit.
1 ist in diesem Fall 100% und 0.5 = 50% etc.
Ich habe ein VB Script gefunden und dieses in AutoIt umgesetzt.
Allerdings habe ich noch einen Fehler in Line 20 denke ich.
Wenn ich nur 1 gleiches Wort benutze für $str1 + $str2 stimmt das Programm (Ergebnis 1), aber wenn ich mehrere verwende nicht mehr (Ergebnis 0.7 bei 2 gleichen Wörtern)
Der VB Code ist hier zu finden: LINK (Solution 1)
Ich weiß leider nicht genau wie ich:
j = str2.IndexOf(" "c, j) + 1
richtig nach AutoIt übersetze. Bin für jede Hilfe dankbar und noch dankbarer für eine Antwort ohne RTFM Gelaber.
AutoIt
Func Compare($str1, $str2)
$str1Length = StringLen($str1)
$str2Length = StringLen($str2)
$str1Chars = _StringExplode($str1, "", 0)
$str2Chars = _StringExplode($str2, "", 0)
Local $count
Local $hits = 0
Local $i = 0, $j = 0
If $str1Length >= $str2Length Then $count = $str1Length
If $str1Length < $str2Length Then $count = $str2Length
For $i = 0 To $str1Length - 1
If $str1Chars[$i] = " " Then
$i += 1
;$j = $str2.IndexOf(" ", $j) + 1
$j = StringInStr($str2, " ", 0, 1, $j) + 1
$hits += 1
EndIf
While $j < $str2Length And $str2Chars[$j] <> " "
If $str1Chars[$i] = $str2Chars[$j] Then
$hits += 1
$j += 1
ExitLoop
Else
$j += 1
EndIf
WEnd
If Not ($j < $str2Length And $str2Chars[$j] <> " ") Then
$j -= 1
EndIf
Next
Return Round(($hits / $count), 2)
EndFunc ;==>Compare
Alles anzeigen