473,748 Members | 8,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

what is the fastest way to remove a value from a string array? something
like:

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

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

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?

thanks,

Craig
Nov 20 '05 #1
1 19021
Hi,
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.Str ingbuidler 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.Remo ve(0, 1))
MsgBox(str)

Dim MyStringBuilder As New StringBuilder(" Hello World!")
MyStringBuilder .Remove(5, 7)
MsgBox(MyString Builder.ToStrin g)

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

http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconusingstrin gbuilderclass.a sp

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
13947
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of the array can vary depending on the parameters passed. What I need to do is loop through the returned array and if applicable write the array element to the screen.
3
1451
by: David P. Donahue | last post by:
I'm trying to come up with the best (fastest, as this code will be run often) way to accomplish the following: I have a dynamic string array X (as one grabbed from a GetFiles() or GetDirectories() function call), which could have anywhere from 0 to maybe 250 elements in it. I also have a statically-defined string array Y which currently has 309 elements in it, but may grow over time. I need to look through X and remove all elements...
3
3808
by: Don | last post by:
My user control has a combobox with an arraylist attached to it along with custom add and remove methods. The "Add" method is working great. However I don't understand why the "Remove" method isn't working. It neither removes the item from the arraylist nor from the combobox like it's supposed to do. A couple of notes: cbx is the name of the combobox within my usercontrol, file is the name of the arraylist within my usercontrol. To try...
3
1754
by: Nikolay Petrov | last post by:
I have a string array, which I need to save to a file. The array may grow to thousands of elements. My question is what is the fastest way to save it as text file? The StreamWriter accepts String as parameter, but converting the array to a single string takes a lot of time (by using a For loop and concatenating the string). How this can be done faster? P.S. Every element of string array should be in separate row of the file. So the...
3
14007
by: Tony | last post by:
I have this code: Dim elementi() As String = Split(book, "pages") I have to do remove first item from array elementi ... any help? Thanks
5
28386
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through each element but I am having issues using redim to adjust the new array. Any help or example code would be greatly appreciated. thanks!
1
5695
by: Jeff User | last post by:
Hi ..net 1.1 I have a simple string array like string myArray = CallToWebServiceThat_Returns_Elements; I want to remove an item from the array and also remove its position. I can search the array and find the index of desired string, but how can I remove? Do I have to somehow create a new array that is smaller and then copy
2
3030
by: novacreatura | last post by:
Hi, I have a project that's supposed to create a program for a "Dating Service". The first part of the program is to read a textfile of profiles which include names, age, etc...into a string array, and be able to add,edit,remove to the textfile of profiles during runtime. What would be the most efficient way to do this to make it easiest as possible to make changes to the textfile during time and access elements of the array?
6
6111
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or more minutes. 'REMOVE DUBLICATED VALUE FROM ARRAY +++++++++++++++++ Dim col As New Scripting.Dictionary Dim ii As Integer = 0
0
8987
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9316
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9241
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.