StringFind - method of the Pm object
Description:
Returns the position of the first character of searched text in the string.
Syntax:
Long StringFind(String sValue, String sSearch, Long nStart, [String sParams])
Parameters:
sValue | (String) Source string expression. |
sSearch | (String) Searched string |
nStart | (Long) The position of character in searched string specifies the start of the search.
The value -2 means the last character of the string (for reverse search). |
sParams | [optional] (String) Additional search parameters. Entries are in the KeyVal format, for example reverse:1;
reverse:n; - Allows to specify the search direction.
reverse:0; (default) - Forward search direction.
reverse:1; - Backward search direction. |
---|
Return value:
-1 - the string was not found
n - the position number of found text (zero-based index)
Example1:
JavaScriptVBScriptSelect and copy to clipboard
var sVal = "PROMOTIC is fun!";
var nRes = Pm.StringFind(sVal, "is", 0);
// nRes contains 9
Dim sVal
sVal = "PROMOTIC is fun!"
Dim nRes
nRes = Pm.StringFind(sVal, "is", 0)
' nRes contains 9
Example2:
Forward search direction.
JavaScriptVBScriptSelect and copy to clipboard
var iStart = 0;
while (true)
{
iStart = Pm.StringFind("/b1/b2/b3", "/b", iStart);
if (iStart == -1)
{
break;
}
Pm.Debug("iStart=" + iStart);
iStart++;
}
// iStart=0
// iStart=3
// iStart=6
Dim iStart
iStart = 0
Do While true
iStart = Pm.StringFind("/b1/b2/b3", "/b", iStart)
If iStart = -1 Then
Exit Do
End If
Pm.Debug("iStart=" & iStart)
iStart = iStart + 1
Loop
' iStart=0
' iStart=3
' iStart=6
Example3:
Backward search direction.
JavaScriptVBScriptSelect and copy to clipboard
var iStart = -2;
while (true)
{
iStart = Pm.StringFind("/b1/b2/b3", "/b", iStart, "reverse:1;");
if (iStart == -1)
{
break;
}
Pm.Debug("iStart=" + iStart);
iStart--;
}
// iStart=6
// iStart=3
// iStart=0
Dim iStart
iStart = -2
Do While true
iStart = Pm.StringFind("/b1/b2/b3", "/b", iStart, "reverse:1;")
If iStart = -1 Then
Exit Do
End If
Pm.Debug("iStart=" & iStart)
iStart = iStart - 1
Loop
' iStart=6
' iStart=3
' iStart=0