471,624 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

remove an element from an array

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
Nov 21 '05 #1
3 2042
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" wrote:
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

Nov 21 '05 #2
"Jeremy" <je****@ninprodata.com> schrieb:
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", " "))
....
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3
Herfried, perfect. Thanks.

Jeremy

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:ON*************@TK2MSFTNGP12.phx.gbl...
"Jeremy" <je****@ninprodata.com> schrieb:
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", " "))
...
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Sam Collett | last post: by
11 posts views Thread by koperenkogel | last post: by
7 posts views Thread by Derek Basch | last post: by
4 posts views Thread by eksamor | last post: by
14 posts views Thread by oLgAa25 | last post: by
11 posts views Thread by Richard Maher | last post: by
3 posts views Thread by Barkingmadscot | last post: by
6 posts views Thread by tedpottel | last post: by
1 post views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.