Solved

HashTable Remove - Search Functionality.

Posted on 2004-04-14
2
306 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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