Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use Quick Search Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
18-May-03
Category
Algorithm
Language
Delphi All Versions
Views
83
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Attila T.P.

Quick Search string searching

Answer:
1   
2   procedure TForm1.QuickSearch(const AText, APattern: string);
3   var
4     i, k, N, M: integer;
5     v_found: boolean;
6     v_Shift: array[0..255] of byte;
7   
8     procedure InitShift;
9     var
10      x: byte;
11      j, M: integer;
12    begin
13      M := Length(APattern);
14      x := 0;
15      while x <> 255 do
16      begin
17        v_Shift[x] := M + 1;
18        x := Succ(x);
19      end;
20      v_Shift[x] := M + 1;
21      j := 0;
22      while j < M do
23      begin
24        inc(j);
25        v_Shift[Ord(APattern[j])] := M + 1 - j;
26      end;
27    end;
28  begin
29    InitShift;
30    i := 0;
31    k := 0;
32    M := Length(APattern);
33    N := Length(AText);
34    while (i <= N - M + 1) and (k < M) do
35    begin
36      if AText[i + k] = APattern[1 + k] then
37        inc(k)
38      else
39      begin
40        i := i + v_Shift[ord(AText[i + M])];
41        k := 0;
42      end;
43    end;
44    v_found := (k = M);
45    //  if v_found then
46    //  begin
47    //    RichEdit1.SelStart := i - 1;
48    //    RichEdit1.SelLength := M;
49    //  end;
50  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC