Using PowerShell to find the differences in strings

Question:

So I’m playing around with Compare-Object, and it works fine for comparing files. But what about just strings? Is there a way to find the difference between strings? CompareTo() is good about reporting that there is a difference, but not what the difference is. For example:

Nothing returned.

Any way to let me know about the actual difference between the strings, not just that there is a difference?

Answer:

Perhaps something like this:

The function returns -1 if the two strings are equal or the position of the first difference between the two strings. If you want case-insensitive comparisons, you would need to use -eq instead of -ceq and -ne instead of -cne.

Source:

Using PowerShell to find the differences in strings by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply