remove an element from an array

  • Thread starter Thread starter Jeremy
  • Start date Start date
J

Jeremy

I'm trying to parse a sentence and want to remove selected words from the
middle.

Consider:

dim a() as object = split(mySentence)

for each w in a()
select case w
case w.startswith("X")
'code to remove this specific word from the array
end select
next

result = join(a)

Can't find a way to remove the word. Any help out there?

I'm now looking at arrayList, which might have the methods I need, but
haven't figured out how to do the split trick.

Jeremy
 
I would first use replace to get rid of any double spaces then use split to
split the sentence up into an array of words based as a space as the
delimiter.
 
Jeremy said:
I'm trying to parse a sentence and want to remove selected words from the
middle.

Consider:

dim a() as object = split(mySentence)

for each w in a()
select case w
case w.startswith("X")
'code to remove this specific word from the array
end select
next

result = join(a)

Can't find a way to remove the word. Any help out there?

\\\
Dim al As New ArrayList()
al.InsertRange(0, Split("Hello World Test", " "))
For Each Item As String In al
MsgBox(Item)
Next Item
///

- or -

\\\
Imports System.Collections.Specialized
..
..
..
Dim s As New StringCollection()
s.AddRange(Split("Hello World Test", " "))
....
///
 
Herfried, perfect. Thanks.

Jeremy

Herfried K. Wagner said:
\\\
Dim al As New ArrayList()
al.InsertRange(0, Split("Hello World Test", " "))
For Each Item As String In al
MsgBox(Item)
Next Item
///

- or -

\\\
Imports System.Collections.Specialized
.
.
.
Dim s As New StringCollection()
s.AddRange(Split("Hello World Test", " "))
...
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top