Solved

HashTable Remove - Search Functionality.

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Page navigation in windows phone 8.1 application not working. 5 24
Hey Audio! 3 29
.NET 2008 VB and C# 6 28
insert value of checklistbox checked 4 27
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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