Core Function LastIndexOf
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> LastIndexOf( <expression>, <needle>, <pos>, <case>, <count> ) </pre> === Description === Reports the index of the last occurrence of the specified string in the current s...") |
m (1 revision) |
||
(3 intermediate revisions by one user not shown) | |||
Line 61: | Line 61: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
my $str = "FoX The quick brown FoX"; | my $str = "FoX The quick brown FoX"; | ||
− | println( LastIndexOf($str, "fox", strlen($str), true) ); | + | println( LastIndexOf($str, "fox", strlen($str) - 1, true) ); |
+ | </syntaxhighlight> | ||
+ | |||
+ | Another example | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $pathName = "C:\\WINDOWS\\TEMP\\WSREWE.DAT"; | ||
+ | $position = LastIndexOf($pathName, "\\") + 1; | ||
+ | $fileName = substr($pathName, $position); | ||
+ | print("$fileName\n"); //Prints: WSREWE.DAT | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
LastIndexOf( <expression>, <needle>, <pos>, <case>, <count> )
Contents |
Description
Reports the index of the last occurrence of the specified string in the current string.
Parameters specify the starting search position in the current string and the type of search to use for the specified string.
expression
The string to use.
needle
The string to find.
pos
Optional; Position to start the search from within the expression.
Default: expression length - 1
case
Optional; Case sensitive option
false = Case sensitive search
true = Case insensitive search
Default: false
count
Optional; The amount of characters to check before quitting the search
Default: pos + 1
Return Value
Success: Returns last position of the found string in the string.
Failure: Returns -1.
Remarks
None.
Example
Case sensitive
println( LastIndexOf("FoX The quick brown FoX", "FoX") );
Case insensitive
my $str = "FoX The quick brown FoX"; println( LastIndexOf($str, "fox", strlen($str) - 1, true) );
Another example
$pathName = "C:\\WINDOWS\\TEMP\\WSREWE.DAT"; $position = LastIndexOf($pathName, "\\") + 1; $fileName = substr($pathName, $position); print("$fileName\n"); //Prints: WSREWE.DAT