Core Function IndexOf

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
  
Reports the index of the first occurrence of the specified character in the current string.
+
Reports the index of the first occurrence of the specified character/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.
 
Parameters specify the starting search position in the current string and the type of search to use for the specified string.
Line 15: Line 15:
 
=== needle ===
 
=== needle ===
  
The character to find (If you pass a string here the first character of it will be used as the needle).
+
The character or string to find.
  
 
=== pos ===
 
=== pos ===
Line 53: Line 53:
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
println(  IndexOf("The quick brown FoX", "X")  );
 
println(  IndexOf("The quick brown FoX", "X")  );
 +
</syntaxhighlight>
 +
 +
<syntaxhighlight lang="sputnik">
 +
println(  IndexOf("qThe Theqt Thei", "qt")  );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 59: Line 63:
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
println(  IndexOf("The quick brown FoX", "x", 0, true)  );
 
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]]

Revision as of 22:45, 20 August 2013

IndexOf( <expression>, <needle>, <pos>, <case>, <count> )

Contents

Description

Reports the index of the first occurrence of the specified character/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 character or 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 character 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)   );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox