Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    compare 2 comma separated strings (A2k3 SP2)

    Hi All,
    Is there an easier way to compare 2 comma separated strings to each other than to use the split function on each and then loop through the values one by one?
    Example: Are any of these values (1, 3, 4, 8) in this string (2, 3, 5, 8, 9, 10)? If so how many?
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: compare 2 comma separated strings (A2k3 SP2)

    You could expand the "search in" string, like this: <code>", 2, 3, 5, 8, 9, 10, "</code> (i.e., pre- and postfix it with <code>", "</code>).
    Then use the split function on the other string and loop through the resulting array.
    Within the loop, pre- and postfix the array item with <code>", "</code> (example: <code>", 3, "</code>) and use InStr to determine if it occurs in the expanded "search in" string. Increment a counter if it does.
    This way, you only need to split one of the strings.

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    Brookings, South Dakota, USA
    Posts
    449
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: compare 2 comma separated strings (A2k3 SP2)

    Thank you Hans.........cool. <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>
    That will cut down the coding a bit as well as make it a bit easier to maintain.
    <IMG SRC=http://www.wopr.com/w3tuserpics/gdrezek_sig.jpg>
    "Those who dance are considered insane by those who can't hear the music" - George Carlin

Posting Permissions

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