Below function can be used to merge two string array,This function will combine two string array into one,eleminating duplicate element.
'Pass the Destination and Source string array that need to be merged Private Function MergeArray(ByVal arrDestination() As String, ByVal arrSource() As String) As String() Dim intElement As Integer Try For intElement = 0 To arrSource.Length - 1 'Check if element already exist,in no Re-Dimension the Destination array and add the New element in it. If Array.IndexOf(arrDestination, arrSource(intElement)) = -1 Then ReDim Preserve arrDestination(arrDestination.Length) arrDestination(arrDestination.Length - 1) = arrSource(intElement) End If Next 'Return the Resultant mergred array Return arrDestination Catch exc As Exception Throw exc End Try End Function
'e.g Dim arrArray1() As String = {"My", "Name"} Dim arrArray2() As String = {"Name", "Is", "ABC"} 'After mergin above array the fginal value in arrArray1 will be {"My,"Name", "Is", "ABC"} arrArray1 = MergeArray(arrArray1, arrArray2)
PS:Same logic can be used to merge anytype of array.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|