Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 669

•  TDictionary Custom Sort  5 800

•  Fast Watermark Sources  5 603

•  3D Designer  8 217

•  Sik Screen Capture  5 913

•  Patch Maker  6 388

•  Айболит (remote control)  6 378

•  ListBox Drag & Drop  5 237

•  Доска для игры Реверси  94 551

•  Графические эффекты  6 570

•  Рисование по маске  5 643

•  Перетаскивание изображений  4 759

•  Canvas Drawing  5 135

•  Рисование Луны  4 863

•  Поворот изображения  4 411

•  Рисование стержней  3 116

•  Paint on Shape  2 360

•  Генератор кроссвордов  3 228

•  Головоломка Paletto  2 551

•  Теорема Монжа об окружностях  3 328

•  Пазл Numbrix  2 200

•  Заборы и коммивояжеры  2 849

•  Игра HIP  1 820

•  Игра Go (Го)  1 740

•  Симулятор лифта  2 072

•  Программа укладки плитки  1 798

•  Генератор лабиринта  2 240

•  Проверка числового ввода  1 925

•  HEX View  2 225

•  Физический маятник  1 911

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Выполнить обратный поиск строки в TRichEdit



Оформил: DeeCo

 {+------------------------------------------------------------ 
 | Function FindTextBackwards 
 | 
 | Parameters : 
 |   findWhat: text to find 
 |   inString: string to find it in 
 |   startAt : character index to start at (1-based) 
 |   caseSensitive: determines whether search is case-sensitive 
 |   words   : if true the characters immediately surrounding 
 |             a found location must not be alphanumeric 
 | Returns    : 
 |   character index (1-based) of first character of a found 
 |   location, or 0, if the text was not found. 
 | Description: 
 |   Performs a simple sequential search for a string in a larger 
 |   string, starting at the specified position and working towards 
 |   the start of the string. 
 | Error Conditions: none 
 | Created: 27.02.99 by P. Below 
 +------------------------------------------------------------}

 function FindTextBackwards(findWhat, inString : string;
   startAt : integer;
   caseSensitive, words : boolean): integer;
 var
   i, patternlen, findpos : integer;
   lastchar, firstchar : char;
 begin
   Result := 0;  { assume failure }
   patternlen := Length(findWhat);

   { Do a few sanity checks on the parameters }
   if (patternlen = 0) or
     (startAt < patternlen) or
     (Length(inString) < patternlen) then
     Exit;

   if not caseSensitive then
    begin
     { convert both strings to lower case }
     findWhat := AnsiLowercase(findWhat);
     inString := AnsiLowercase(inString);
   end; { If }

   i := startAt;
   lastchar := findWhat[patternlen];
   firstchar := findWhat[1];

   while (Result = 0) and (i >= patternlen) do
    begin
     if inString[i] = lastchar then
      begin
       findPos := i - patternlen + 1;
       if inString[findPos] = firstchar then
        begin
         { We have a candidate. Compare the substring of length 
          patternlen starting at findPos with findWhat. With 
          AnsiStrLComp we can do that without having to copy 
          the substring to a temp string first. }
         if AnsiStrLComp(@findWhat[1], @inString[findPos],
           patternlen) = 0 then
          begin
           { We have a match! }
           Result := findPos;

           if words then
            begin
             { Check the characters surrounding the hit. For the hit 
              to constitute a word they must not be alphanumeric. }
             if (findPos > 1) and
               IsCharAlphanumeric(inString[findPos - 1]) then
              begin
               { Not a match after all, <sigh>. }
               Result := 0;
             end { If }
             else
              begin
               if (i < Length(inString)) and
                 IsCharAlphanumeric(inString[i + 1]) then
                begin
                 { Not a match after all, <sigh>. }
                 Result := 0;
               end; { If }
             end; { Else }
           end; { If }
         end; { If }
       end; { If }
     end; { If }
     Dec(i);
   end; { While }
 end; { FindTextBackwards }

 procedure TForm1.Button1Click(Sender : TObject);
 var
   findPos : integer;
 begin
   findPos := FindTextBackwards(findEdit.Text,
     richedit1.Text,
     richedit1.selstart + 1,
     caseCheckbox.Checked,
     wordsCheckbox.Checked);
   if findPos > 0 then
    begin
     with richedit1 do
      begin
       selstart := findPos - 1;
       sellength := findEdit.GetTextLen;
       Perform(em_scrollcaret, 0, 0);
       SetFocus;
     end;
   end
   else
     ShowMessage('Text not found');
 end;




Похожие по теме исходники

Поисковик

Поиск символа

Поиск файлов

Поиск открытых файлов

 

Findup (поиск дублей)

Дейкстра: поиск кратчайшего пути




Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте