utf8.find
Client-side
Server-side
Shared
Finds 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 the end of the matched string is returned.
Syntax
int, int utf8.find ( string input, string pattern, [ int startpos = 1, boolean plain = false ] )Required Arguments
- input: A string character sequence.
- pattern: A string match pattern (you can disable pattern matching by using the optional fourth argument plain ).
Optional Arguments
NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.
- startpos (default: 1): An integer representing the beginning position.
- plain (default: false): A boolean, if pattern matching should be turned off
Returns
- int: start position
- int: end position
Returns two number values for the beginning and ending position of the matched string, nil otherwise.
Code Examples
shared
This example shows how to search for parts of a string.
print(utf8.find("Hello MTA User", "User")) -- 11, 14print(utf8.find("Hello MTA User", "e")) -- 2, 2print(utf8.find("Hello MTA User", "e", 3)) -- 13, 13print(utf8.find("Привет Привет", "%s")) -- 7, 7print(utf8.find("Привет Привет", "%s", 1, true)) -- nil
-- Comparsion of utf8.find and string.findlocal startpos, endpos = utf8.find("Привет", "и")print(startpos, endpos) -- 3, 3
local startpos, endpos = string.find("Привет", "и")print(startpos, endpos) -- 5, 6