Solved

HashTable Remove - Search Functionality.

Posted on 2004-04-14
2
302 Views
Last Modified: 2010-04-15
Hi,

Here is my Hashtable.

HasTable myHash = new HashTable();

myHash.Add("~Chapter1-example1","A");
myHash.Add("~Chapter1-example2","B");
myHash.Add("~Chapter1-example3","C");
myHash.Add("~Chapter1-example4","D");


myHash.Add("~Chapter2-example1","A");
myHash.Add("~Chapter2-example2","B");
myHash.Add("~Chapter2-example3","C");
myHash.Add("~Chapter2-example4","D");
myHash.Add("~Chapter2-example5","E");



How can i remove all elements with key = "~Chapter1-"

kind of like a partial search, just want to remove all the keys, that start with the following key.



thanks,
steve.
0
Comment
Question by:steve_mick972
2 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 500 total points
ID: 10829467
Afraid you have to loop..

IDictionaryEnumerator en = myHash.GetEnumerator();

while ( en.MoveNext() )
{
         string sKey = (string)en.Key;
         if(sKey.IndexOf("partialkey") == 0)
               myHash.Remove(sKey);
}
0
 
LVL 1

Expert Comment

by:Troy_Lyne
ID: 10836834
Nest hashtables:

myHashCh1.Add("example1","A");
myHashCh1.Add("example2","B");
myHashCh1.Add("example3","C");
myHashCh1.Add("example4","D");

myHashCh2.Add("example1","A");
myHashCh2.Add("example2","B");
myHashCh2.Add("example3","C");
myHashCh2.Add("example4","D");
myHashCh2.Add("example5","E");

myHash.Add("~Chapter1-", myHashCh1);
myHash.Add("~Chapter2-", myHashCh2);
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now