Difference between revisions of "SHIP:Sail:lastIndexOf"

From Serious Documentation
Jump to: navigation, search
(Created page with "__NOTOC__ See Also: *SHIP Sail Home *SHIP Sail Function Home *indexOf(), subStr(), [[SHIP:Sail...")
 
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
See Also:
+
{{SailFuncTableStart|}}<onlyinclude>
*[[SHIP:Sail|SHIP Sail Home]]
+
|{{SailFunc|lastIndexOf}}||{{DataType|Integer}}||style="text-align:center;"|v4.0||Returns the index of the last found occurrence (if any) of a substring within another string, optionally starting at a specified offset. If the substring is not found, -1 is returned.</onlyinclude>
*[[SHIP:Sail:Functions|SHIP Sail Function Home]]
+
|}
*[[SHIP:Sail:indexOf|indexOf()]], [[SHIP:Sail:subStr|subStr()]], [[SHIP:Sail:subString|subString()]]
+
== See Also: ==
 
+
*[[SHIP:Sail|Sail Home]]
== lastIndexOf ==
+
*[[SHIP:Sail:Functions|Sail Functions]]
Returns the index of the last found occurrence (if any) of a substring within another string, optionally starting at a specified offset. If the substring is not found, -1 is returned.
+
*[[SHIP:Sail:String Functions|Sail String Functions]]
 
+
*{{SailFunc|indexOf}}, {{SailFunc|subStr}}, {{SailFunc|subString}}, {{SailFunc|toString}}
 
== Prototype ==
 
== Prototype ==
<code>{{DataType|Integer}} lastIndexOf ({{DataType|String}} original,{{DataType|String}} tofind);</code>
+
<code>{{DataType|Integer}} {{SailFunc|lastIndexOf}}({{DataType|String}} original,{{DataType|String}} tofind);</code>
 
 
<code>{{DataType|Integer}} lastIndexOf ({{DataType|String}} original,{{DataType|String}} tofind, {{DataType|Integer}} offset);</code>
 
  
 +
<code>{{DataType|Integer}} {{SailFunc|lastIndexOf}}({{DataType|String}} original,{{DataType|String}} tofind, {{DataType|Integer}} offset);</code>
 
=== Parameters/Return Value ===
 
=== Parameters/Return Value ===
 
{| class="wikitable" style="margin: 1em 1em;"  
 
{| class="wikitable" style="margin: 1em 1em;"  
Line 31: Line 30:
  
 
== Detailed Description ==
 
== Detailed Description ==
The <code>lastIndexOf ()</code> function returns the index in the original string of last occurrence of the string <code>tofind</code> in the original string, or -1 if the string is not found.
+
The {{SailFunc|lastIndexOf}} function returns the index in the original string of last occurrence of the string <code>tofind</code> in the original string, or -1 if the string is not found.
  
 
An optional <code>offset</code> may be specified, which specifies that the search in the original string begins at that specified offset.  If the offset is negative, the search will begin at offset 0.  If the offset is past the end of the original string, the function will always return -1.
 
An optional <code>offset</code> may be specified, which specifies that the search in the original string begins at that specified offset.  If the offset is negative, the search will begin at offset 0.  If the offset is past the end of the original string, the function will always return -1.
Line 41: Line 40:
 
! scope="col" style="text-align:left" | Notes
 
! scope="col" style="text-align:left" | Notes
 
|-
 
|-
|<code>lastIndexOf ("feb","janfebmar");</code> || 3 ||
+
|<code>lastIndexOf("feb","janfebmar");</code> || 3 ||
 
|-
 
|-
|<code>lastIndexOf ("feb","janfebmarfeb");</code> || 9 || returns last found
+
|<code>lastIndexOf("feb","janfebmarfeb");</code> || 9 || returns last found
 
|-
 
|-
|<code>lastIndexOf ("feb","janfebmar",4);</code> || -1 || starts searching on "ebmar"
+
|<code>lastIndexOf("feb","janfebmar",4);</code> || -1 || starts searching on "ebmar"
 
|-
 
|-
|<code>lastIndexOf ("feb","janfebmar",-1);</code> || 3 || starts searching at 0
+
|<code>lastIndexOf("feb","janfebmar",-1);</code> || 3 || starts searching at 0
 
|-
 
|-
|<code>lastIndexOf ("feb","janfebmar",23);</code> || -1 || past end, always returns -1
+
|<code>lastIndexOf("feb","janfebmar",23);</code> || -1 || past end, always returns -1
 
|}
 
|}
 +
 +
[[Category:Numeric Functions]]
 +
[[Category:String Functions]]

Latest revision as of 16:01, 10 October 2016

Function Returns Introduced Description
lastIndexOf Integer v4.0 Returns the index of the last found occurrence (if any) of a substring within another string, optionally starting at a specified offset. If the substring is not found, -1 is returned.

See Also:

Prototype

Integer lastIndexOf(String original,String tofind);

Integer lastIndexOf(String original,String tofind, Integer offset);

Parameters/Return Value

Parameter Data Type Description
original String String to search in
tofind String String to find in original
offset Integer index in original string 0...(length-1)
Return Integer Index of last occurrence of tofind in original, or -1 if not found

Detailed Description

The lastIndexOf function returns the index in the original string of last occurrence of the string tofind in the original string, or -1 if the string is not found.

An optional offset may be specified, which specifies that the search in the original string begins at that specified offset. If the offset is negative, the search will begin at offset 0. If the offset is past the end of the original string, the function will always return -1.

Examples

Example Result Notes
lastIndexOf("feb","janfebmar"); 3
lastIndexOf("feb","janfebmarfeb"); 9 returns last found
lastIndexOf("feb","janfebmar",4); -1 starts searching on "ebmar"
lastIndexOf("feb","janfebmar",-1); 3 starts searching at 0
lastIndexOf("feb","janfebmar",23); -1 past end, always returns -1