Comparing values between two arrays

Discussion in 'ASP .Net' started by darrel, Dec 23, 2005.

  1. darrel

    darrel Guest

    I have two comma delimted strings that I need to compare individual values
    between the two. I assume the solution is likely to put them into an array?
    If so, do I need to loop through one, comparing the other, or is there some
    sort of compare function already in .net?

    For instance, I have these strings:

    str1: ,3,6,12,17,

    str2: ,7,8,12,

    I need to check to see if any of the values in str1 exists in str2.

    Off the top of my yead, I could split str2 into an array, then loop through
    the values in the array using the instr function to see if they exist in
    str1.

    -Darrel
     
    darrel, Dec 23, 2005
    #1
    1. Advertisements

  2. darrel

    Karl Seguin Guest

    there are a lot of ways to do this. You could split on array loop through
    it and look for a non-negative IndexOf of the value within the other string.

    you could split both and loop through both

    you could split them and load them in arraylists and use Contains (which
    merely loops)

    Karl
     
    Karl Seguin, Dec 23, 2005
    #2
    1. Advertisements

  3. darrel

    darrel Guest

    Looping it is!

    Just realized that it's not really that big of an issue. Split one of the
    two, loop through the other comparing.

    -Darrel
     
    darrel, Dec 23, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.