Core Function IndexOfAny
From Sputnik Wiki
(Difference between revisions)
m (1 revision) |
|||
(4 intermediate revisions by one user not shown) | |||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
− | Reports the index of the first occurrence of any | + | Reports the index of the first occurrence of any characters or array of strings in a specified string. |
=== expression === | === expression === | ||
Line 13: | Line 13: | ||
=== needle === | === needle === | ||
− | The characters to find. | + | The characters to find (as a string) or an array of strings to find. |
=== pos === | === pos === | ||
Line 39: | Line 39: | ||
=== Return Value === | === Return Value === | ||
− | Success: Returns position of the found character in the string. | + | Success: Returns position of the found character or string in the string. |
Failure: Returns -1. | Failure: Returns -1. | ||
Line 52: | Line 52: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
+ | // Find characters | ||
println( IndexOfAny("The quick brown FoX", "qki") ); | println( IndexOfAny("The quick brown FoX", "qki") ); | ||
println( IndexOfAny("The quick brown FoX", "qkie") ); | println( IndexOfAny("The quick brown FoX", "qkie") ); | ||
+ | // Find string | ||
+ | println( IndexOfAny("The quick brown FoX", array("FoX")) ); | ||
+ | // Find array of strings | ||
+ | println( IndexOfAny("The quick brown FoX", array("brown", "FoX")) ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 59: | Line 64: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
+ | // Find characters | ||
println( IndexOfAny("The quick brown FoX", "QK", 0, true) ); | println( IndexOfAny("The quick brown FoX", "QK", 0, true) ); | ||
println( IndexOfAny("The quick brown FoX", "EQ", 0, true) ); | println( IndexOfAny("The quick brown FoX", "EQ", 0, true) ); | ||
+ | // Find string | ||
+ | println( IndexOfAny("The quick brown FoX", array("fox"), 0, true) ); | ||
+ | // Find array of strings | ||
+ | println( IndexOfAny("The quick brown FoX", array("brown1", "fox"), 0, true) ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Latest revision as of 12:37, 14 June 2015
IndexOfAny( <expression>, <needle>, <pos>, <case>, <count> )
Contents |
Description
Reports the index of the first occurrence of any characters or array of strings in a specified string.
expression
The string to use.
needle
The characters to find (as a string) or an array of strings 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
Default: expression length - pos
Return Value
Success: Returns position of the found character or string in the string.
Failure: Returns -1.
Remarks
None.
Example
Case sensitive
// Find characters println( IndexOfAny("The quick brown FoX", "qki") ); println( IndexOfAny("The quick brown FoX", "qkie") ); // Find string println( IndexOfAny("The quick brown FoX", array("FoX")) ); // Find array of strings println( IndexOfAny("The quick brown FoX", array("brown", "FoX")) );
Case insensitive
// Find characters println( IndexOfAny("The quick brown FoX", "QK", 0, true) ); println( IndexOfAny("The quick brown FoX", "EQ", 0, true) ); // Find string println( IndexOfAny("The quick brown FoX", array("fox"), 0, true) ); // Find array of strings println( IndexOfAny("The quick brown FoX", array("brown1", "fox"), 0, true) );