Core Function LastIndexOf

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
m (1 revision)
 
(2 intermediate revisions by one user not shown)
Line 62: Line 62:
 
my $str = "FoX The quick brown FoX";
 
my $str = "FoX The quick brown FoX";
 
println(  LastIndexOf($str, "fox", strlen($str) - 1, 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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox