Click here to Skip to main content
15,915,603 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Pls help me.
40+5-3;5+10-2 is the fist array data.

42|13 is second array data.

Second array data 42 is first array data 40+5-3 calculation result and then

second array data 13 is first array data 5+10-3 calculation result.

I wish to be below result in third array
42|40|5|3|13|5|10|2
---------------
In third array
eg:
Calculation result | Statement|Calculation Result | Statement
--------------
Third array is union of first and second array.

Pls reply me.

Thanks..
Posted

The Union method excludes the duplicates as given here
http://msdn.microsoft.com/en-us/library/bb341731.aspx#Y100[^]
So, if there is a statement say "35+10-3" which gives the result "42", then this will not be included in the union of statements and results. Concat method can be used. If it is used all the elements from first array are listed first and then the elements of the second array are listed. But as given in the question, result, statement order is required. In which case I think the following code can be used for better control on the order of the elements
VB
Dim statements As String() = {"40+5-3", "5+10-2", "35+10-3"}
Dim results As String() = {"42", "13", "42"}
'Dim resultsStatements As String() = New String(Math.Min(statements.Length, results.Length) * 2 - 1) {}
'Ensure that the statements and results are of same length
If statements.Length <> results.Length Then
	Console.WriteLine("The number of Statements and number of Results should be equal")
	Return
End if
Dim resultsStatements As String() = New String(statements.Length * 2 - 1) {}
Dim i As Integer = 0
'While i < statements.Length AndAlso i < results.Length
While i < statements.Length 
	resultsStatements(i * 2) = results(i)
	resultsStatements(i * 2 + 1) = statements(i)
	i += 1
End While
For Each element As String In resultsStatements
	Console.WriteLine(element)
Next
'Output
'42
'40+5-3
'13
'5+10-2
'42
'35+10-3
 
Share this answer
 
v2
Comments
ProEnggSoft 10-Apr-12 11:24am    
Good answer. 5!
VJ Reddy 10-Apr-12 19:39pm    
Thank you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900