472,355 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,355 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 2709
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

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.