MyChat Scripts Engine: Pos, MyChat Scripts Engine: Pos, searching a substring in a string
Searching the specified substring in a string. The letter case is important.
Syntax
function Pos(sSubSt, sSt: string): integer;
Parameters and return values
Parameter |
Type |
Value |
sSubSt |
string |
substring that you need to find; |
sSt |
string |
source string for searching. |
Function result
Returns the index of the substring. If the substring is not found, the function returns 0. Numeration of characters begins from 1.
Example
const
sSt = 'Yesterday all my troubles seemed so far away, now it looks as though they''re here to stay.';
sFind = 'away';
var
x: integer;
begin
mLogScript('Original string: "' + sSt + '"', '');
mLogScript('Try to find the "' + sFind + '" string', '');
x := pos(sFind, sSt);
if x = 0 then mLogScript('not found', '')
else mLogScript('String "' + sFind + '" is found. Position: ' + inttostr(x), '');
end.
Script work result
[14:26:35] (Log "Pos"): Original string: "Yesterday all my troubles seemed so far away, now it looks as though they're here to stay."
[14:26:35] (Log "Pos"): Try to find the "away" string
[14:26:35] (Log "Pos"): String "away" is found. Position: 41
See also
Created with the Personal Edition of HelpNDoc: Create iPhone web-based documentation