Core Function StrPos

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(flags)
Line 28: Line 28:
  
 
1 = Case insensitive search
 
1 = Case insensitive search
 +
 +
2 = Find last match instead of first
 +
 +
(Can add flags together)
  
 
Default: 0 (Case sensitive)
 
Default: 0 (Case sensitive)
Line 42: Line 46:
  
 
=== Example ===
 
=== Example ===
 +
 +
Find First:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
$RET = StrPos("The quick brown FoX", "foX", 0, 1);
 
$RET = StrPos("The quick brown FoX", "foX", 0, 1);
 +
println( $RET );
 +
</syntaxhighlight>
 +
 +
Find Last:
 +
 +
<syntaxhighlight lang="sputnik">
 +
// Flag 1 for case ignore case then flag 2 for find last instead of first
 +
$RET = StrPos("FoX the quick brown FoX", "foX", 0, 1 | 2);
 
println( $RET );
 
println( $RET );
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Core Function]]
 
[[Category:Core Function]]

Revision as of 21:00, 28 January 2013

StrPos( <haystack>, <needle>, <offset>, <flags> )

Contents

Description

Find the position of the first occurrence of a substring in a string

Parameters

haystack

The string to search in.

needle

The string to search for.

offset

Optional; Search will start this number of characters counted from the beginning of the string.

(Cannot be negative)

Default: 0

flags

1 = Case insensitive search

2 = Find last match instead of first

(Can add flags together)

Default: 0 (Case sensitive)

Return Value

Returns the position of where the needle exists relative to the beginning of the haystack (independent of offset). Also note that string positions start at 0, and not 1.

Return -1 on failure (such as did not find)

Remarks

None.

Example

Find First:

$RET = StrPos("The quick brown FoX", "foX", 0, 1);
println( $RET );

Find Last:

// Flag 1 for case ignore case then flag 2 for find last instead of first
$RET = StrPos("FoX the quick brown FoX", "foX", 0, 1 | 2);
println( $RET );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox