Results 1 to 2 of 2

Thread: [2005] Comparing string arrays

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    58

    [2005] Comparing string arrays

    I can't get my head around this. Can anyone help?

    Given two string arrays, I need to create a third array/string which contains the additions...

    e.g.

    ARRAY1
    Bob
    Jane
    Paul

    ARRAY2
    Bob
    Mary
    Jane
    Paul
    John

    I need a routine that will tell me that Mary and John have been added - e.g. a string result of "Mary,John"

    Also, it's possible that some items originally in ARRAY1 might not be present in ARRAY2.

    e.g.

    ARRAY1
    Bob
    Jane
    Paul

    ARRAY2
    Mary
    Jane
    John

    Again, all I want to know is that Mary and John were added to the array - I don't need to know that Bob and Paul were removed.

    Can anyone help?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Comparing string arrays

    You need to loop through the elements of array 2 and call Array.IndexOf to see if that element is in array 1. If Array.IndexOf returns -1 then the value is not in the array.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width