Core Function StrPos

From Sputnik Wiki
Revision as of 21:00, 28 January 2013 by UberFoX (Talk | contribs)
Jump to: navigation, search
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