Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread Efficient search of text
Mon, Jan 23 2017 8:23 AMPermanent Link

Matthew Jones

I have to search for some text in an object which has 12 strings, mixed case. There may be hundreds of these, and I'd like to do it as fast as possible. The instant solution is Pos(search, itemtext), but that is case sensitive. So I am currently using Lowercase on the search term, and then doing Lowercase on each of the 12 values, each time.

szSearch := LowerCase(szSearch);
for nLoop in all items do
begin
 bFound := Pos(szSearch, LowerCase(m_szHumanName)) > 0;
 if not bFound then
   bFound := Pos(szSearch, LowerCase(m_szAddress1)) > 0;
   // repeat 12 times
end;

Now I could write a case insensitive Pos, but I suspect that would actually add more code. Anyone know of a better way to do this?

Hmm, I could append all the strings and lowercase that, but would it really help?


--

Matthew Jones
Wed, Jan 25 2017 2:05 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< I have to search for some text in an object which has 12 strings, mixed case. There may be hundreds of these, and I'd like to do it as fast as possible. The instant solution is Pos(search, itemtext), but that is case sensitive. So I am currently using Lowercase on the search term, and then doing Lowercase on each of the 12 values, each time.  >>

That's the best solution for now, and what is normally recommended for such operations in native JS.  You can also use regular expressions in JS, but that gets messy with escaping, etc.

Tim Young
Elevate Software
www.elevatesoft.com
Image