MyChat Scripts: функция PosEx, поиск подстроки в строке со смещением
Поиск подстроки в строке со смещением. Регистр букв имеет значение.
Синтаксис
function PosEx(const sSubSt, sOriginal: string; iOffset: cardinal): integer;
Параметры и возвращаемые значения
| Параметр | Тип | Значение | 
| sSubSt | string | какую подстроку нужно найти; | 
| sOriginal | string | исходная строка, в которой производится поиск; | 
| iOffset | integer | смещение, начиная с которого нужно делать поиск, должно быть больше или равно единице. | 
Результат функции
Индекс найденной подстроки. Если подстрока не найдена или смещение меньше либо равно нулю, возвращается ноль. Нумерация символов в исходной строке начинается с единицы.
Пример
const
  ORIGINAL = 'Head high, protest line,' + #13#10 + 
             'Freedom scribbled on your sign,' + #13#10 +
             'Headline New York Times,'  + #13#10 +
             'Standing on the edge of a revolution.' + #13#10 +
       
             'Hey! Hey! Just obey,' + #13#10 +
             'Your secrets safe with the NSA,' + #13#10 +
             'In God we trust or the CIA?' + #13#10 +
             'Standing on the edge of a revolution.';
  
  FIND     = 'revolution';
var
  x, iOffset, iCount: integer;
begin
  iCount  := 0;
  iOffset := 1;
  
  mLogScript(ORIGINAL, '');
  mLogScript('Finding a word "' + FIND + '"...', '');
  
    repeat
      x := PosEx(FIND, ORIGINAL, iOffset);
      
        if x <> 0 then begin
          inc(iCount);
          iOffset := x + 1;
        end;
    until x = 0;
    
  mLogScript('Total entries: ' + IntToStr(iCount), '');
end.
Результат работы скрипта
[11:50:22] (Log "PosEx"): Head high, protest line,
Freedom scribbled on your sign,
Headline New York Times,
Standing on the edge of a revolution.
Hey! Hey! Just obey,
Your secrets safe with the NSA,
In God we trust or the CIA?
Standing on the edge of a revolution.
[11:50:22] (Log "PosEx"): Finding a word "revolution"...
[11:50:22] (Log "PosEx"): Total entries: 2
[11:50:22] (Run "PosEx"): Время выполнения скрипта: 4 мс
[11:50:22] (Run "PosEx"): Скрипт выполнен успешно.