Skip to main content
added 359 characters in body
Source Link
Tim Schmelter
  • 461.8k
  • 79
  • 719
  • 980

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

Result:

 (0) "B" String (1) "C" String (2) "E" String (3) "G" String 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates also a new array.

Edit: Here's an example which removes elements based on the index, assuming you have an int[] with all indices that you want to delete from the first array:

Dim deleteIndices = {0, 3, 5, 7} ' remove elements with index 0,3,5,7 Dim result = original. Where(Function(str, index) Not deleteIndices.Contains(index)). ToArray() 

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

Result:

 (0) "B" String (1) "C" String (2) "E" String (3) "G" String 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates also a new array.

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

Result:

 (0) "B" String (1) "C" String (2) "E" String (3) "G" String 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates also a new array.

Edit: Here's an example which removes elements based on the index, assuming you have an int[] with all indices that you want to delete from the first array:

Dim deleteIndices = {0, 3, 5, 7} ' remove elements with index 0,3,5,7 Dim result = original. Where(Function(str, index) Not deleteIndices.Contains(index)). ToArray() 
added 91 characters in body
Source Link
Tim Schmelter
  • 461.8k
  • 79
  • 719
  • 980

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

Result:

 (0) "B" String (1) "C" String (2) "E" String (3) "G" String 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates alsoalso a new array.

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates also a new array.

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

Result:

 (0) "B" String (1) "C" String (2) "E" String (3) "G" String 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates also a new array.

Source Link
Tim Schmelter
  • 461.8k
  • 79
  • 719
  • 980

I would suggest to use LINQ for this, your code becomes more readable and maintanable then.

Since you haven't shown how you've filtered the first array, i assume for the example that you want to remove all "A","D","F","H" (case sensitive):

Dim original = {"A", "B", "C", "D", "E", "F", "G", "H"} ' remove A,D,F,H Dim result = (From str In original Where Not {"A", "D", "F", "H"}.Contains(str)).ToArray() 

End result should be preferably not in a new array but a "ReDim" of the original array: ("B")("C")("E")("G")

Of course above creates a new array, but Redim creates also a new array.