Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HashTable Remove - Search Functionality.

Posted on 2004-04-14
2
Medium Priority
?
315 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

916 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