string.find
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 | <nowiki>
string.find("hello world","hello")
</nowiki>
|
||
Output | 1 5 |
|
|||
Returns nil, because it starts at pos 2. | |||
Code | <nowiki>
string.find("hello world","hello",2)
</nowiki>
|
||
Output | nil |
|
|||
Returns the start and end pos of the letter "l" in the word world. | |||
Code | <nowiki>
string.find("hello world","l",-6)
</nowiki>
|
||
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 | <nowiki>
string.find("%l","%l",1,true)
</nowiki>
|
||
Output | 1 2 |
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.