Core Function IndexOf
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> IndexOf( <expression>, <needle>, <pos>, <case>, <count> ) </pre> === Description === Reports the index of the first occurrence of the specified character in the current s...") |
m (1 revision) |
||
(8 intermediate revisions by one user not shown) | |||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
− | Reports the index of the first occurrence of the specified | + | Reports the index of the first occurrence of the specified string in a string. |
+ | |||
+ | Parameters specify the starting search position in the current string and the type of search to use for the specified string. | ||
=== expression === | === expression === | ||
Line 13: | Line 15: | ||
=== needle === | === needle === | ||
− | The | + | The string to find. |
=== pos === | === pos === | ||
Optional; Position to start the search from within the expression. | Optional; Position to start the search from within the expression. | ||
+ | |||
+ | Default: 0 | ||
=== case === | === case === | ||
Line 23: | Line 27: | ||
Optional; Case sensitive option | Optional; Case sensitive option | ||
− | + | false = Case sensitive search | |
− | + | true = Case insensitive search | |
− | Default: | + | Default: false |
=== count === | === count === | ||
Line 35: | Line 39: | ||
=== Return Value === | === Return Value === | ||
− | Success: Returns position of the found | + | Success: Returns position of the found string in the string. |
Failure: Returns -1. | Failure: Returns -1. | ||
Line 44: | Line 48: | ||
=== Example === | === Example === | ||
+ | |||
+ | Case sensitive | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
println( IndexOf("The quick brown FoX", "X") ); | println( IndexOf("The quick brown FoX", "X") ); | ||
+ | println( IndexOf("qThe Theqt Thei", "qt") ); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Case insensitive | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | println( IndexOf("The quick brown FoX", "x", 0, true) ); | ||
+ | println( IndexOf("qThe Theqt Thei", "THEI", 0, true) ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
IndexOf( <expression>, <needle>, <pos>, <case>, <count> )
Contents |
Description
Reports the index of the first occurrence of the specified string in a 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: 0
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
Return Value
Success: Returns position of the found string in the string.
Failure: Returns -1.
Remarks
None.
Example
Case sensitive
println( IndexOf("The quick brown FoX", "X") ); println( IndexOf("qThe Theqt Thei", "qt") );
Case insensitive
println( IndexOf("The quick brown FoX", "x", 0, true) ); println( IndexOf("qThe Theqt Thei", "THEI", 0, true) );