
|
<<
Index
>>
|
FutureBasic
|
instr, instr$
|
|
function
|
|
Syntax
foundPosition =
instr(
startPos, targetCFString, searchCFString [, searchOptions
] )
foundPosition =
instr$(
startPos, targetPascalString or targetContainer$$, searchPascalString or searchContainer$$)
Description
This function searches for the first occurrence of searchCFString, searchPascalString or searchContainer$$ within targetCFString, targetPascalString or targetContainer$$, starting at character position startPos. The string search is case-sensitive by default, but see searchOptions parameter in instr syntax.
instr parameters
Parameter
|
Description |
startPos |
The character position to start the search.
If startPos is less than 0, it's treated as 0 for a forward search, and the last character for a backward search.
|
targetString |
The string to search. |
searchString |
The string to search for. If the NSRegularExpressionSearch search option is used, this is the regex pattern. |
searchOptions |
Search options can be combined using '+':
NSCaseInsensitiveSearch
NSLiteralSearch
NSBackwardsSearch
NSAnchoredSearch
NSNumericSearch
NSDiacriticInsensitiveSearch
NSWidthInsensitiveSearch
NSForcedOrderingSearch
NSRegularExpressionSearch N.B. If this option is set, no other options can apply except NSCaseInsensitiveSearch and NSAnchoredSearch .
|
instr return value
If a match is found, the function returns the character position where the match begins. If no match is found, returns NSNotFound
.
instr example
CFStringRef string, searchString
string = @"An I for an i and a tooth for a tooth"
searchString = @"i"
print instr( 0, string, searchString )
print instr( 0, lcase(string), lcase(searchString) )
print instr( 0, string, searchString, NSCaseInsensitiveSearch )
print instr( 22, string, searchString, NSBackwardsSearch )// searches backwards from character 22 to 0
print instr( 0, string, @"[aeiou]", NSRegularExpressionSearch ) // returns position of first, lowercase vowel in string
HandleEvents
instr$ parameters
Parameter
|
Description |
startPos |
The character position to start the search. If startPos is less than 1, it's treated as 1. |
targetString |
The string to search. |
searchString |
The string to search for. |
instr$ return value
If a match is found, the function returns the character position where the match begins. If no match is found, returns 0.
See also
indexf; mid; left; right