Core Function InStr

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(occurrence)
(Example)
Line 51: Line 51:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$location = InStr("How much wood could a woodchuck chuck is a woodchuck could chuck wood?", "wood", 0, 3)
+
$location = InStr("How much wood could a woodchuck chuck is a woodchuck could chuck wood?", "wood", 0, 3);
Println("Search result:" , $location) ; Find the 3rd occurance of "wood"
+
Println("Search result:" , $location); // Find the 3rd occurance of "wood"
 
+
$result = InStr("I am a String", "RING")
+
$result = InStr("I am a String", "RING");
Println("Search result:" , $result)
+
Println("Search result:" , $result);
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 20:45, 18 November 2011

InStr( <string>, <substirng>, <casesense>, <occurrence>, <start>, <count>

Contents

Description

Checks if a string contains a given substring.

Parameters

string

The string to evaluate.

substring

The substring to search for.

casesense

Optional; Flag to indicate if the operations should be case sensitive. 0 = not case sensitive, using the user's locale (default) 1 = case sensitive 2 = not case sensitive, using a basic/faster comparison

occurrence

Optional; Which occurrence of the substring to find in the string. Use a negative occurrence to search from the right side.

The default value is 1 (finds first occurrence).

start

Optional; The starting position of the search.

count

Optional; The number of comparisons to make.

Return Value

Success: Returns the position of the substring.

Failure: Returns 0 if substring not found or -1 if Invalid "occurance" parameter given.

Remarks

The first character position is 1.

Example

$location = InStr("How much wood could a woodchuck chuck is a woodchuck could chuck wood?", "wood", 0, 3);
Println("Search result:" , $location); // Find the 3rd occurance of "wood"
 
$result = InStr("I am a String", "RING");
Println("Search result:" , $result);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox