Donate SIGN UP

Vb Net Array

Avatar Image
erylle | 15:17 Sat 26th Sep 2015 | Technology
1 Answers
I have a problem. I dont know how to get the intersection part of array. Example I input in set A: 9,8,7,7,6 and set B: 5, 8,4,3
the output or answer will be appear on another form. The another form have an image which is circle where the set are located. Set A will be : 9,7,6 Set B: 5,4,3 and there intersection is : 8. I hope someone can help me with my problem tho.
Gravatar

Answers

Only 1 answerrss feed

Best Answer

No best answer has yet been selected by erylle. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
If I understand your problem correctly, i.e.

- take Set A and compare it to Set B to identify the matching array elements, which in your given sets is the number 8.
- Print out the results displaying the two sets and highlight the matching array element(s) e.g. proposed output is "SetA(9 7 7 6 (8) 5 4 3)SetB"

If so, the following vb.net program code may be what you are seeking (note, it is has not been tested, but does contain the logic required and may need some tweaking)

' vb.net Code:-
' ======================
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text

' Initally Create two integer arrays.
Dim setA() As Integer = {9,8,7,7,6}
Dim SetB() As Integer = {5,8,4,3}

' Find the set intersection of the two arrays.
Dim intersection As IEnumerable(Of Integer) = setA.Intersect(SetB)

'String buffer to hold intersect data
Dim Intersectoutput As New System.Text.StringBuilder

'Get setA() minus the intersect data
Dim setAless = setA.Except(intersection)

'Get setB() minus the intersect data
Dim setBless = setB.except(intersection) 'String buffer for setB() less the intersect data

'String buffers to hold sets A and B minus Intersect data
Dim setAoutput As New System.Text.StringBuilder
Dim setBoutput As New System.Text.StringBuilder


For Each id As Integer In intersection ' build text string of intersect data
Intersectoutput.Append(id)
Next


For Each id As Integer In SetAless ' build text string of SetAless less Intersect data
setAoutput.Append(id)
Next


For Each id As Integer In SetBless ' build text string of SetBless less Intersect data
setBoutput.Append(id)
Next


' Display the output in format as "SetA(9 7 7 6 (8) 5 4 3)SetB"
' complete with intersect data displayed in centre paranthesis

Console.WriteLine (setAoutput.ToString & " (" & Intersectoutput.ToString & ") " & setBless.ToString & ")SetB")
Console.ReadKey()


Only 1 answerrss feed

Do you know the answer?

Vb Net Array

Answer Question >>