473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

.FindString implementation

Hello!

I have recently come across two very nice methods in ListBox control:
..FindString and .FindStringExact
it is very usefull for me, and I would like to use it in some other
situations.

Where could I find an implementation of thiese methods or other similar
solutions. I would like to use such methods without ListBox - only with a
simple
Collection like SortedList (key and value). I have created a simple
implementation myself but I'm not sure it's that quick.

SortedList searchList = new SortedList();

// [...] - fill the list
foreach (DictionaryEntry de in searchList) {

string strKey = (string) de.Key;

if (strKey.StartsWith(strSearched)) {

return de.Value; break;

} else {

if (strKey.CompareTo(strSearched) > 0) break;

}

}
Marcin Floryan
marcin at floryan dot neostrada dot pl
Nov 16 '05 #1
1 2753
Marcin,

This is not as fast as it could be. What I would do is get the keys,
and then perform a binary search on it. Basically, since the keys should be
ordered (it is a sorted list, right), you can basically use a binary search.

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

"Marcin Floryan" <marcin[REMOVE]@floryan.neostrada.pl> wrote in message
news:O%****************@TK2MSFTNGP15.phx.gbl...
Hello!

I have recently come across two very nice methods in ListBox control:
.FindString and .FindStringExact
it is very usefull for me, and I would like to use it in some other
situations.

Where could I find an implementation of thiese methods or other similar
solutions. I would like to use such methods without ListBox - only with a
simple
Collection like SortedList (key and value). I have created a simple
implementation myself but I'm not sure it's that quick.

SortedList searchList = new SortedList();

// [...] - fill the list
foreach (DictionaryEntry de in searchList) {

string strKey = (string) de.Key;

if (strKey.StartsWith(strSearched)) {

return de.Value; break;

} else {

if (strKey.CompareTo(strSearched) > 0) break;

}

}
Marcin Floryan
marcin at floryan dot neostrada dot pl

Nov 16 '05 #2

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

Similar topics

0
by: Rene Aguirre | last post by:
Hello everybody, I had this problem using the FindString funcion of a wxChoice object on wxPython: * I have Windows 98 * I read a text file edited on a Japanese computer, but only uses...
17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
9
by: Anon Email | last post by:
Hi people, I'm learning about header files in C++. The following is code from Bartosz Milewski: // Code const int maxStack = 16; class IStack
2
by: Jorge | last post by:
Hello I have a little problem i have a checkedlistbox with several repeated items. The code below only selects the first ocurrence While reader.Read For i = 0 To...
0
by: commanderjason | last post by:
I am converting a .net winforms app to wpf I make use of the System.Windows.Forms.ComboBox.FindString but am unable to find anything that accomplishes that in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...

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.