473,467 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

help in search&replace for ArrayList

Jon
Hi,
I have an arrayList that holds an ArrayObject with (Qty & ItemCode).
e.g.
arrayList.Add(New ArrayObject(Qty, ItemCode)

However, I want to search the arrayList and check if the ItemCode already
exist on the arrayList, then simply increase the Qty by 1.

For example:
I have in my arraylist:
index 0, object {1, "1111"}
index 1, object {1, "2222"}
index 2, ojbect {3, "7777"}

Now i want to add another object say {4, "2222"} to the arrayList, but
instead of adding it as NEW item to the list, I want to able to find the
index and replace the Qty, so index 1, will now looks like {5, "2222"}.

I hope u see what i mean....
Any help is appreciated, Many thanks in advance !
Jon
May 3 '06 #1
4 1488
Jon
just wonder are there any faster method to search like using indexOf? and
instead of looping each item and compare the ItemCode?

thanks
May 3 '06 #2
If your list is sorted, you can use a Binary Search to get the item very
quickly. If it isn't sorted, you might want to consider using a hashtable
instead of an array, using the first number as the key. But this will only
work if you think your numbers are unique.

"Jon" <Jo*@discussions.microsoft.com> wrote in message
news:51**********************************@microsof t.com...
just wonder are there any faster method to search like using indexOf? and
instead of looping each item and compare the ItemCode?

thanks

May 3 '06 #3
If you are using 2005 a KeyedCollection would make the task simple

"Jon" wrote:
Hi,
I have an arrayList that holds an ArrayObject with (Qty & ItemCode).
e.g.
arrayList.Add(New ArrayObject(Qty, ItemCode)

However, I want to search the arrayList and check if the ItemCode already
exist on the arrayList, then simply increase the Qty by 1.

For example:
I have in my arraylist:
index 0, object {1, "1111"}
index 1, object {1, "2222"}
index 2, ojbect {3, "7777"}

Now i want to add another object say {4, "2222"} to the arrayList, but
instead of adding it as NEW item to the list, I want to able to find the
index and replace the Qty, so index 1, will now looks like {5, "2222"}.

I hope u see what i mean....
Any help is appreciated, Many thanks in advance !
Jon

May 3 '06 #4
Or use a Generic Dictionary class. Something like this:

Dim MyObjects As New List(Of String, Integer)

If MyObject.Keys.Contains("2222") Then
Dim newQty As Integer = MyObjects("2222") + 5
MyObjects("2222") = newQty
Else
MyObjects.Add("2222", 5)
End If

May 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Zenobia | last post by:
Hello I want a search & replace text in source code for several files in several directories. It would seem that both Dreamweaver MX 6 and GoLive 6 offer this feature but not for .aspx file...
3
by: tchurm | last post by:
Hi Pythonistas, Here's my problem: I'm using a version of MOOX Firefox (http://moox.ws/tech/mozilla/) that's been modified to run completely from a USB Stick. It works fine, except when I...
1
by: Tomomichi Amano | last post by:
Hello. I want to make replace & search functions in my text editor. Thanks to the kind people here at the newsgroup, I was able to make the function. But I was not able to understand how to...
2
by: Jan | last post by:
Hello! I am looking for a way to do a search&replace in ASCII-Files by a vb.net 2005 programm. Of coarse I can open the files, loop to every line, make a replace, and save the line. But I wonder...
6
by: DataSmash | last post by:
Hello, I need to search and replace 4 words in a text file. Below is my attempt at it, but this code appends a copy of the text file within itself 4 times. Can someone help me out. Thanks! #...
2
by: Ola K | last post by:
Hi guys, I wrote a script that works *almost* perfectly, and this lack of perfection simply puzzles me. I simply cannot point the whys, so any help on it will be appreciated. I paste it all here,...
16
by: Proaccesspro | last post by:
I'm trying to create a search & replace function in Access. Specifically, I want to search for a specific SSN and replace it, if found. Not sure how to code the "guts" of it. Here is what I have...
6
by: simon.robin.jackson | last post by:
Ok. I need to develop a macro/vba code to do the following. There are at least 300 corrections and its expected for this to happen a lot more in the future. Therefore id like a nice...
2
by: huberkev11 | last post by:
I have a similar problem as posted in the following thread: http://bytes.com/topic/c/answers/691469-c-search-replace-function The difference is that I need to search for words not just a...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
1
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...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.