Difference between revisions of "String.find"
(Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === Looks for the first match of pattern in the string s. If it finds a match, then find returns the indic...") |
|||
Line 7: | Line 7: | ||
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices. | If the pattern has captures, then in a successful match the captured values are also returned, after the two indices. | ||
<source lang="lua"> | <source lang="lua"> | ||
− | (numbers) | + | (numbers) = string.find(s,pattern,init,plain) |
</source> | </source> | ||
− | '''s | + | '''s''': (string) string where to find a pattern ''''''<br/> |
− | '''pattern | + | '''pattern''': (string) pattern to find ''''''<br/> |
− | '''init | + | '''init''': (number) index where to start searching for pattern '''optional'''<br/> |
− | '''plain | + | '''plain''': (bool) if true, then it simply matches substring without any special symbols (default = false) '''optional'''<br/> |
'''Returns''' (numbers) indexes of occurrence of the pattern or nil<br/> | '''Returns''' (numbers) indexes of occurrence of the pattern or nil<br/> |
Revision as of 10:17, 23 August 2018
Available since: Gideros 2011.6
Description
Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.
(numbers) = string.find(s,pattern,init,plain)
's: (string) string where to find a pattern '
'pattern: (string) pattern to find '
init: (number) index where to start searching for pattern optional
plain: (bool) if true, then it simply matches substring without any special symbols (default = false) optional
Returns (numbers) indexes of occurrence of the pattern or nil