+ Reply to Thread
Results 1 to 9 of 9

Compare two strings

  1. #1
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126

    Compare two strings

    Looking for a line of code or formula to check if two strings have the same characters but not necessarily in the same order (without using a loop or sorting the strings)

    e.g.

    ABCDE
    BEADC

    should result in a match

    Thanks

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Compare two strings

    Hi

    Assumes that your data is in A1:A2, and you only have 5 characters in the string. If you have a variable number, then let us know.

    =AND(ISNUMBER(SEARCH(MID(A1,ROW(A1:A5),1),A2))) (array entered).

    HTH

    rylo

  3. #3
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126

    Re: Compare two strings

    Thanks rylo.

    Works only if the two strings are the same length and no repeats. For example comparing AAAAA with ABCDE return true!

    Also not sure about the extra functions and the array formula, but shouldn't this simplified version work just as well for any number of characters?

    =ISNUMBER(SEARCH(MID(A1,1,1),A2))

    Thanks
    Last edited by matrex; 10-12-2012 at 12:32 PM.

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Compare two strings

    Hi

    So there are a few more things to consider.

    1) if the strings are not the same length, then is that an automatic fail?
    2) if there are repeats is that an automatic fail?
    3) is this a one way compare, or both way (ie are you comparing all the items in A1 with A2, or does A2 also have to work with A1)

    are there any more things to consider?

    rylo

  5. #5
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126

    Re: Compare two strings

    rylo

    It should be a 100% identical match (character for character) except that the characters do not have to be in the same order. So yes the length of the string should be the same

    Also the characters could be numeric

    ABCDE & BDCAE ==> YES
    AACDE & BDCAE ==> NO
    1234 & 3412 ==> YES

    Thanks

  6. #6
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126

    Re: Compare two strings

    Still waiting for a solution....

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Compare two strings

    Hi

    This does seem to be extremely cumbersome, but I think it does get you there. Array entered of course.

    Please Login or Register  to view this content.
    rylo

  8. #8
    Forum Contributor
    Join Date
    06-07-2008
    Posts
    126

    [SOLVED] Re: Compare two strings

    Works great as long as the strings are in column A. Wonder if it could be adapted to work on any cells

    Thanks for your continued assistance
    Last edited by matrex; 10-16-2012 at 05:37 PM. Reason: Solved

  9. #9
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Compare two strings

    Hi

    Of course, just put in the relevant cell references as required.

    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1