string.find
Jump to navigation
Jump to search
string.find Function | |
---|---|
Syntax string.find() Colon notation: sentence:find() | |
Returns | number |
API | string |
Source | Lua (source) |
Finds a pattern in a sentence.
|
|||
Returns the start and end pos of the word. | |||
Code | string.find("hello world","hello")
|
||
Output | 1 5 |
|
|||
Returns nil, because it starts at pos 2. | |||
Code | string.find("hello world","hello",2)
|
||
Output | nil |
|
|||
Returns the start and end pos of the letter "l" in the word world. | |||
Code | string.find("hello world","l",-6)
|
||
Output | 10 10 |
|
|||
Normaly it would find only the letter "l". When you turn the pattern finding off, it finds the letter "%" as well. | |||
Code | string.find("%l","%l",1,true)
|
||
Output | 1 2 |