0

I am working on a project that will compare two strings as well as outputting the position of the differences.

So far, I have obtained a function here, that will show the position of the first difference of the two strings. Is there a way of getting the position of multiple differences in two strings?

Example:

My name is John

My jame is Johm
AJennings1
  • 159
  • 1
  • 2
  • 10
  • Within the for loop, append the indexes when the characters are different into an array and return that instead of returning the index of the first difference – arco444 Aug 04 '17 at 09:12

1 Answers1

1
$a="My name is John"
$b="My jame is Johm"

for ($i=0;$i-lt$a.Length;$i++){
    if ($a[$i] -ne $b[$i]){
        "Mismatch at $i : $($a[$i]) -> $($b[$i])"
    }
}

the linked answer just stops the loop when it finds one, remove return and it works.

Mismatch at 3 : n -> j
Mismatch at 14 : n -> m
colsw
  • 3,216
  • 1
  • 14
  • 28