473,750 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check hashtable keys by ignoring the case

Hi

Can any one say how to check a hashtable by ignoring the case of key
supplied. I want the following requirement

It should not allow the user to do the following
Hashtable table = new Hashtable();
a) table.Add("one" ,1);
b) table.Add("One" ,1);

by default it executes the above two statements with out any
problem. But my intention is to throw an exception when the table contains
the key by ignoring the case. Is there any way to implement like above?
Thanks in advance

Srikanth
Nov 16 '05 #1
4 4746
Srikanth,

What you want to do is call the constructor that takes an IComparer,
passing a CaseInsensitive Comparer instance. Then, when you call Add with
the same key, it will throw an exception.

It should be noted that particular constructor is marked as Obsolete in
..NET 2.0, in favor of a new interface (only available in 2.0).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Srikanth" <ta*****@inooga .com> wrote in message
news:eX******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi

Can any one say how to check a hashtable by ignoring the case of key
supplied. I want the following requirement

It should not allow the user to do the following
Hashtable table = new Hashtable();
a) table.Add("one" ,1);
b) table.Add("One" ,1);

by default it executes the above two statements with out any
problem. But my intention is to throw an exception when the table contains
the key by ignoring the case. Is there any way to implement like above?
Thanks in advance

Srikanth

Nov 16 '05 #2
You must convert keys to upper case (or lower case) before storing them...

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Srikanth" <ta*****@inooga .com> escribió en el mensaje
news:eX******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi

Can any one say how to check a hashtable by ignoring the case of key
supplied. I want the following requirement

It should not allow the user to do the following
Hashtable table = new Hashtable();
a) table.Add("one" ,1);
b) table.Add("One" ,1);

by default it executes the above two statements with out any
problem. But my intention is to throw an exception when the table contains
the key by ignoring the case. Is there any way to implement like above?
Thanks in advance

Srikanth

Nov 16 '05 #3
That would require excessive maintinence. You can use a
CaseInsensitive Comparer (passed through the constructor) which would treat
the keys in a case-insensitive manner.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Carlos J. Quintero [.NET MVP]" <ca*****@NOSPAM sogecable.com> wrote in
message news:u$******** ********@TK2MSF TNGP09.phx.gbl. ..
You must convert keys to upper case (or lower case) before storing them...

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
"Srikanth" <ta*****@inooga .com> escribió en el mensaje
news:eX******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi

Can any one say how to check a hashtable by ignoring the case of key
supplied. I want the following requirement

It should not allow the user to do the following
Hashtable table = new Hashtable();
a) table.Add("one" ,1);
b) table.Add("One" ,1);

by default it executes the above two statements with out any
problem. But my intention is to throw an exception when the table
contains
the key by ignoring the case. Is there any way to implement like above?
Thanks in advance

Srikanth


Nov 16 '05 #4
The easiest way:
System.Collecti ons.Specialized .CollectionsUti l.CreateCaseIns ensitiveHashtab le()

"Srikanth" <ta*****@inooga .com> wrote in message
news:eX******** ********@TK2MSF TNGP10.phx.gbl. ..
Hi

Can any one say how to check a hashtable by ignoring the case of key
supplied. I want the following requirement

It should not allow the user to do the following
Hashtable table = new Hashtable();
a) table.Add("one" ,1);
b) table.Add("One" ,1);

by default it executes the above two statements with out any
problem. But my intention is to throw an exception when the table contains
the key by ignoring the case. Is there any way to implement like above?
Thanks in advance

Srikanth

Nov 16 '05 #5

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

Similar topics

1
9943
by: _eee_ | last post by:
I'm looking for a way to step through a hashtable while adding items to the table (This precludes using enumerators. They don't like HashTable alterations while they are active). There must be an internal structure that can be accessed sequentially, like an array. Is it accessible? Or maybe there is another construct that will allow this. The main reason I'm using a HashTable is to eliminate duplicate entries. (This is why I had...
0
341
by: choyk1 | last post by:
I intended to save properties of an object to a Hashtable. In this case, keys and values are not fixed types and I cannot use SortedList. I have no idea what order the .NET framework add items to Hashtable when Add(key, value) method is applied. Monitoring the position items are added, I cannot find if key is the standard or value. I thought basically Hashtable function acts randomly, therefore the order will be changed unexpectedly. ...
10
1280
by: William Stacey [MVP] | last post by:
Doing a project that makes heavy use of domain names such as "www.yahoo.com." Domain names preserve case but are concidered equal if names are same but case is different. I know I can store these names as keys in a hashtable with case insens comparer and CaseInsensitiveHashCodeProvider. That works fine. The benifit is I can store the domain name and not worry about case and return the user supplied case without storing an state, etc. ...
2
24636
by: MFRASER | last post by:
How do I go about looping through a hash table and removing items. I know how do this in a collectionbase, but can't iterate through the hash table with out getting an error. Here is my sample code for a collection base for(int i = this.Values.Count; i > 0 ; i--) { //Set local object
16
696
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
0
3530
by: mnmnm1951 | last post by:
I am working with Sharepoint Services and am trying to add the fileversion Metadata to the Versions.aspx page using the example from the SDK. I have not done much with hashtables but it all looks straightforward in the SDK. The code segment added is below. The commented out lines (<!-- )are for testing and work correctly. i.e. I can create a NEW hashtable, add items to it, and display them on the Versions.aspx page. When I try to...
5
3838
by: Gerrit Beuze | last post by:
Hi all, Using C# 1.1: I need a fast way of determining whether a string is in a list of approx 150 keyword like strings. in two versions: one case-sensitive, the other one case-insenstive. I thought of loading the keywords in a Hastable as Keys with null values, and then use Hastable.ContainsKey(string) but Hashtable does not seem to support case-insentive keys.
8
2079
by: Martin Pöpping | last post by:
Hello, I´ve implemented a Hashtable with Int-Keys and Double Values. Now I want to get the i-th Int-Key of my hashtable. How do I do that? I tried it like that: ICollection intKeys = myHashtable.Keys;
8
5869
by: Ashish Khandelwal | last post by:
-----See below code, string str = "blair"; string strValue = "ABC"; string str1 = "brainlessness"; string strValue1 = "XYZ"; int hash = str.GetHashCode() ; // Returns 175803953 int hash1 = str1.GetHashCode(); // Returns 175803953 Hashtable ht = new Hashtable(); ht.Add(hash ,strValue); ht.Add(hash1,strValue1); // ****ERROR****
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9397
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9344
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8264
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6810
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4716
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3327
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 we have to send another system

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.