Jeg har flikket den her sammen i VBScript.
Den er beregnet til websites, men du kan nok godt tilpasse den til andre behov. I det mindste kan det give dig en fornemmelse af, hvordan man gør det.
Det meste af koden skulle gerne være selvforklarende. Du har jo trods alt erfaring med VBScript.
arrResult = CompareStrings("Dette er en tekst", "Dette en tekst er", True)
If arrResult(0) Then strColor = "#FA0" Else strColor = "#F00"
For i = 0 To UBound(arrResult(2))
If arrResult(0) Then strText = Mid(arrResult(1), i + 1, 1) Else strText = arrResult(1)(i)
blnDifferent = arrResult(2)(i)
If blnDifferent Then strText = "<span style=""color:" & strColor & ";"">" & strText & "</span>"
If i > 0 AND NOT arrResult(0) Then strText = " " & strText
Response.Write(strText)
Next
Response.Write("<br />")
For i = 0 To UBound(arrResult(4))
If arrResult(0) Then strText = Mid(arrResult(3), i + 1, 1) Else strText = arrResult(3)(i)
blnDifferent = arrResult(4)(i)
If blnDifferent Then strText = "<span style=""color:" & strColor & ";"">" & strText & "</span>"
If i > 0 AND NOT arrResult(0) Then strText = " " & strText
Response.Write(strText)
Next
Function CompareStrings(strText, strCompareTo, blnCompareByChar)
If NOT blnCompareByChar Then
'Word comparison
arrTextWords = Split(strText, " ")
arrCompareToWords = Split(strCompareTo, " ")
ReDim arrTextWordDiff(UBound(arrTextWords))
ReDim arrCompareToWordDiff(UBound(arrCompareToWords ))
If UBound(arrTextWords) > UBound(arrCompareToWords) Then
intIndex = 0
Do While intIndex <= UBound(arrCompareToWords)
blnResult = arrCompareToWords(intIndex) <> arrTextWords(intIndex)
arrTextWordDiff(intIndex) = blnResult
arrCompareToWordDiff(intIndex) = blnResult
intIndex = intIndex + 1
Loop
Do While intIndex <= UBound(arrTextWords)
arrTextWordDiff(intIndex) = False
intIndex = intIndex + 1
Loop
ElseIf UBound(arrTextWords) < UBound(arrCompareToWords) Then
intIndex = 0
Do While intIndex <= UBound(arrTextWords)
blnResult = arrCompareToWords(intIndex) <> arrTextWords(intIndex)
arrTextWordDiff(intIndex) = blnResult
arrCompareToWordDiff(intIndex) = blnResult
intIndex = intIndex + 1
Loop
Do While intIndex <= UBound(arrCompareToWords)
arrCompareToWords(intIndex) = False
intIndex = intIndex + 1
Loop
Else
intIndex = 0
Do While intIndex <= UBound(arrTextWords)
blnResult = arrCompareToWords(intIndex) <> arrTextWords(intIndex)
arrTextWordDiff(intIndex) = blnResult
arrCompareToWordDiff(intIndex) = blnResult
intIndex = intIndex + 1
Loop
End If
CompareStrings = Array(blnCompareByChar, arrTextWords, arrTextWordDiff, arrCompareToWords, arrCompareToWordDiff)
Else
'Char comparison
ReDim arrTextCharDiff(Len(strText))
ReDim arrCompareToCharDiff(Len(strCompareTo))
If Len(strText) > Len(strCompareTo) Then
intIndex = 1
Do While intIndex <= Len(strCompareTo)
blnResult = Mid(strCompareTo, intIndex, 1) <> Mid(strText, intIndex, 1)
arrTextCharDiff(intIndex) = blnResult
arrCompareToCharDiff(intIndex) = blnResult
intIndex = intIndex + 1
Loop
Do While intIndex <= Len(strText)
arrTextCharDiff(intIndex) = False
intIndex = intIndex + 1
Loop
ElseIf Len(strText) < Len(strCompareTo) Then
intIndex = 1
Do While intIndex <= Len(strText)
blnResult = Mid(strCompareTo, intIndex, 1) <> Mid(strText, intIndex, 1)
arrTextCharDiff(intIndex) = blnResult
arrCompareToCharDiff(intIndex) = blnResult
intIndex = intIndex + 1
Loop
Do While intIndex <= Len(strCompareTo)
arrCompareToCharDiff(intIndex) = False
intIndex = intIndex + 1
Loop
Else
intIndex = 1
Do While intIndex <= Len(strCompareTo)
blnResult = Mid(strCompareTo, intIndex, 1) <> Mid(strText, intIndex, 1)
arrTextCharDiff(intIndex) = blnResult
arrCompareToCharDiff(intIndex) = blnResult
intIndex = intIndex + 1
Loop
End If
CompareStrings = Array(blnCompareByChar, strText, arrTextCharDiff, strCompareTo, arrCompareToCharDiff)
End If
End Function