By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,196 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,196 IT Pros & Developers. It's quick & easy.

fastest, easiest way to remove item from a string array?

P: n/a
what is the fastest way to remove a value from a string array? something

dim x as string() = {"A","B","C","D"}

'remove C
x.Clear(x, x.IndexOf(x, "C"), 1)

1). if i'm calling x.clear, do i need to keep specifying x in the
..indexof method? can i use me.?
2). does Clear resize the array?


Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
I looked at your code. Basically when you say

dim x as string() = {"A","B","C","D"}

It is an array of strings. Basically "A" is a string by itself. You could
also say something like

dim x as string() = {"abcd","hello"}

So now when you say x.clear(...), it will basically just make the index
that you specifly null. It will not resize the array.
But if you are just looking to create a string and manipulate its
characters then there are two ways to do it.

1) Use the System.String class and create a string as follows

Dim x as new String("Hello World")

then you can call x.remove(0,1), this will basically return a string with
one character removed. The origninal x will remain unchanged.The drawback
to using the String class is that it will generate a new string for every
string operation. So the other way to do is as follows

2) You can use the System.Text.Stringbuidler class. This class will do all
the operations on the source string. It is more like direct mainpulation of
the string stored in memory For example
Dim str As New String("hello world!")
MsgBox(str.Remove(0, 1))

Dim MyStringBuilder As New StringBuilder("Hello World!")
MyStringBuilder.Remove(5, 7)

Str will still have the same value, but mystringbuilder will have only the
resultant value of the remove operation.

The following link has a detailed description

Anand Balasubramanian
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.