m
Move page script moved page API strfind to WoW:API strfind without leaving a redirect
(Added an example to demonstrate use with patterns) |
m (Move page script moved page API strfind to WoW:API strfind without leaving a redirect) |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{luaapi}} | ||
string.find(s, pattern [, init [, plain]]) | string.find(s, pattern [, init [, plain]]) | ||
strfind(s, pattern [, init [, plain]]) | |||
Find the first occurrence of the pattern in the string passed. If an instance of the pattern is found a pair of values representing the start and end of the string is returned. If the pattern cannot be found nil is returned. | Find the first occurrence of the pattern in the string passed. If an instance of the pattern is found a pair of values representing the start and end of the string is returned. If the pattern cannot be found nil is returned. | ||
| Line 18: | Line 19: | ||
13 13 | 13 13 | ||
The pattern argument can be a regular expression which allows more complex | The pattern argument can be a regular expression which allows more complex searches. See the [http://lua-users.org/wiki/PatternsTutorial Patterns Tutorial on Lua-Users.org] and [[Pattern matching]] for more information. We can turn off the regular expression feature by using the optional fourth argument plain. plain takes a boolean value and must be preceded by init. E.g., | ||
> = string.find("Hello Lua user", "%su") -- find a space character followed by "u" | > = string.find("Hello Lua user", "%su") -- find a space character followed by "u" | ||
| Line 35: | Line 36: | ||
firstWord = "Phase2" | firstWord = "Phase2" | ||
restOfString = "There isn't any need for iterating over this mini-string." | restOfString = "There isn't any need for iterating over this mini-string." | ||