vb.net - How to compare two arrays of string? -


i want compare 2 string arrays. don't know how implement in vb.net.

let's have 2 arrays

dim a() string = {"hello", "how", "are", "you?") dim b() string = {"you", "how", "something else", "you") 

and want compare a() b() see how similar , different (the order of elements not matter, means program not check order of elements , compares if there same elements). code ignore same elements in same string array(like second "you" in array b(). code return elements these same , elements different. in case output message should be:

the same elements "you" , "how"

the different element "something else"

with linq use except() find differences between 2 arrays , intersect() find elements in both arrays.

imports system.linq  module module1     sub main()         dim a() string = {"hello", "how", "are", "you?"}         dim b() string = {"you", "how", "something else", "you"}          console.writeline("a elements not in b: " + string.join(", ", a.except(b)))         console.writeline("b elements not in a: " + string.join(", ", b.except(a)))         console.writeline("elements in both & b: " + string.join(", ", a.intersect(b)))          console.readline()     end sub end module 

results:

a elements not in b: hello, are, you? b elements not in a: you, else elements in both & b: how 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -