Function String Manipulations Class

CompareStrings

Indicate which portions of two strings are the same. Includes the original strings and the marker string all separated by carriage return and line feed characters. Indicates matches with a caret character ("^") in the marker string and indicates differences with a space (" ").

Signature (Visual Basic / VBA)

Public Function CompareStrings( _
      ByVal vStringOne As Variant _
    , ByVal vStringTwo As Variant _
    , Optional ByVal vCompare As Variant _
    ) As Variant

Code Example

       ? CompareStrings("ABCDEFGHI", "ABCFEDGHI")
       ABCDEFGHI
       ABCFEDGHI
       ^^^ ^ ^^^
    that is
       "ABCDEFGHI" + vbCrLf + "ABCFEDGHI" + vbCrLf + "^^^ ^ ^^^"
    or
       "ABCDEFGHI" + Chr$(13) + Chr$(10) + "ABCFEDGHI" + Chr$(13) + Chr$(10) + "^^^ ^ ^^^"

Parameters

Parameter Description
vStringOne One of the strings which is to be compared with the other. Function returns Null if vStringOne is Null or cannot be fixed up to a String.
vStringTwo One of the strings which is to be compared with the other. Function returns Null if vStringTwo is Null or cannot be fixed up to a String.
vCompare specifies the type of string comparison used to determine whether corresponding characters match. vCompare defaults to Binary comparisons if it is missing or Null or cannot be fixed up to a number.

Notes & Version History

Summary Similar to the ContrastStrings function except that the characters used to indicate matches are reversed. Relies upon the DifferenceString function to generate the "marker" string.