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.Contai nsKey(string)
but Hashtable does not seem to support case-insentive keys.
Linear search using a StringCollectio n is too slow for what I'm looking for.
Any suggestions on the data structure to use?
Does the 1.1 framework come with sorted (case insentive) stringlists ?
Thanks in advance,
Gerrit Beuze
ModelMaker Tools 5 3850
"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in
news:ei******** ******@TK2MSFTN GP15.phx.gbl: Any suggestions on the data structure to use? Does the 1.1 framework come with sorted (case insentive) stringlists ?
Coming from Delphi the FCL objects are very specialized and confusing at first compared to
Delphi's Swiss Army Knife TStrings.
Take a look in System.Collecti ons.Specialized , but probably the best depends on the size of your
list, etc.. But I would just store them all lower case (or uppercase) and perform the search using
the same.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programmin g is an art form that fights back"
Make your ASP.NET applications run faster http://www.atozed.com/IntraWeb/
Gerrit,
The hashtable does support a case insensitive comparer. There is an
overload of the constructor which you can pass a new instance of a
CaseInsensitive Comparer and a CaseInsensitive HashcodeProvide r, and this will
give you what you want for the case-insensitive keys.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message
news:ei******** ******@TK2MSFTN GP15.phx.gbl... 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.Contai nsKey(string) but Hashtable does not seem to support case-insentive keys.
Linear search using a StringCollectio n is too slow for what I'm looking for.
Any suggestions on the data structure to use? Does the 1.1 framework come with sorted (case insentive) stringlists ?
Thanks in advance,
Gerrit Beuze ModelMaker Tools
Yep, that should do it,
Thanks,
Gerrit Beuze
ModelMaker Tools The hashtable does support a case insensitive comparer. There is an overload of the constructor which you can pass a new instance of a CaseInsensitive Comparer and a CaseInsensitive HashcodeProvide r, and this will give you what you want for the case-insensitive keys.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message news:ei******** ******@TK2MSFTN GP15.phx.gbl... 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.Contai nsKey(string) but Hashtable does not seem to support case-insentive keys.
Linear search using a StringCollectio n is too slow for what I'm looking for.
Any suggestions on the data structure to use? Does the 1.1 framework come with sorted (case insentive) stringlists ?
Thanks in advance,
Gerrit Beuze ModelMaker Tools
If you don't need/want the overhead of using a HashTable you could put all
the keywords into an array, sort the array, and use Array.BinarySea rch().
You could pass a CaseInsensitive Comparer to BinarySearch(), or you could
store all the keywords in lower case and call ToLower() on the input string
(or use upper case if you'd prefer).
You might also look at using the hash code of your keywords as the key for
the HashTable, which would probably be faster than doing a case-insensitive
comparison on the keys.
"Gerrit Beuze" wrote: Yep, that should do it,
Thanks,
Gerrit Beuze ModelMaker Tools
The hashtable does support a case insensitive comparer. There is an overload of the constructor which you can pass a new instance of a CaseInsensitive Comparer and a CaseInsensitive HashcodeProvide r, and this will give you what you want for the case-insensitive keys.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"Gerrit Beuze" <gerrit[at]modelmaker[dot]demon[dot]nl> wrote in message news:ei******** ******@TK2MSFTN GP15.phx.gbl... 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.Contai nsKey(string) but Hashtable does not seem to support case-insentive keys.
Linear search using a StringCollectio n is too slow for what I'm looking for.
Any suggestions on the data structure to use? Does the 1.1 framework come with sorted (case insentive) stringlists ?
Thanks in advance,
Gerrit Beuze ModelMaker Tools
"KH" <KH@discussions .microsoft.com> wrote in message
news:D3******** *************** ***********@mic rosoft.com... If you don't need/want the overhead of using a HashTable you could put all the keywords into an array, sort the array, and use Array.BinarySea rch().
You could pass a CaseInsensitive Comparer to BinarySearch(), or you could store all the keywords in lower case and call ToLower() on the input string (or use upper case if you'd prefer).
You might also look at using the hash code of your keywords as the key for the HashTable, which would probably be faster than doing a case-insensitive comparison on the keys.
That is how I would do it :)
Mythran This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: 42 |
last post by:
Hi,
Stupid question:
I keep bumping into the desire to create classes and properties with the
same name and the current favored naming conventions aren't
automatically differentiating them... (both are "Pascal Case" with no
leading or trailing qualifiers).
For example... I'll be modelling something, e.g. a computer, and I'll
|
by: Paul |
last post by:
Hi all.
Can someone provide some help on the following as there seems to be many
different methods of acheiving the same outcome.
Basically I am trying to develop a web service which will spawn an exe file
to run an import and then return a result back to the web service, this
would also need the facility to spawn multiple copies of the application
upto a maximum figure..............
|
by: Bob |
last post by:
It's not especially important, but I always like to know the best way of doing
things for when I encounter a case where performance becomes a factor... say I
have a string array and I want to get a distinct list, that is, get a list
without duplicates. In SQL this is easy because it's done for you. In code, what
would be the best practice? Array.Sort(stringarray) followed by n comparisons
collecting on the changes? Or perhaps adding each...
|
by: Rich |
last post by:
The procedure below checks if a character entered into a cell of a
datagridview is contained in a string array of valid characters for this
particular cell. It seems kludgy. I am asking what the best practice would
be. I was thinking I could use an arrayList which has the "contains"
property and do this:
If not arr.Contains(s1) then --- don't continue
but my list of codes might be about 50 char combinations. So I was thinking
a...
|
by: Paul |
last post by:
Hi,
I feel I'm going around circles on this one and would appreciate some other
points of view.
From a design / encapsulation point of view, what's the best practise for
returning a private List<as a property.
Consider the example below, the class "ListTest" contains a private "List<>"
called "strings" - it also provides a public method to add to that list,
| |
by: Steve |
last post by:
I am building an object library for tables in a database. What is the
best practice for creating objects like this?
For example, say I have the following tables in my database:
User:
- Id
- FirstName
- LastName
- CompanyId (many-to-one )
|
by: Andrew Meador |
last post by:
I have a form (Change Card List by Status) with a check box
(cboNOT) and a list box (lstStatus). There is an Open Report button
that opens a report (Report - Change Card List) which uses a query
(SQL -Change Card List).
What I want to do is have the form open the report where a filter
is set to use the values from the check box AND the value selected
from the list box to generate the report.
What I can't figure out is how to use the...
|
by: skanemupp |
last post by:
which is the best way to check if a string is an number or a char?
could the 2nd example be very expensive timewise if i have to check a
lot of strings?
this
value = raw_input()
try:
value = int(value)
|
by: dudeja.rajat |
last post by:
Hi,
How to check if something is a list or a dictionary or just a string?
Eg:
for item in self.__libVerDict.itervalues():
self.cbAnalysisLibVersion(END, item)
where __libVerDict is a dictionary that holds values as strings or
|
by: tig2810 |
last post by:
Hi
I was wondering if someone could let me know the best/correct way of doing this. I have a shortened example of code below:
In the beginning of the class I have a List of string containing all records. I have added each encapsulated field to the list in the set property and I need to maintain the order in the list. Is this way best way to do this? Or should I be doing this another cleaner way. I guess I’m asking for best coding...
|
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...
| |
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,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
| |
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |