Utf8.find
Jump to navigation
Jump to search
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
string 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. For more information on optional arguments, see optional arguments.
- startpos: An integer representing the beginning position.
- plain: A boolean, if pattern matching should be turned off
Returns
Returns two number values for the beginning and ending position of the matched string, nil otherwise.
Example
Click to collapse [-]
ServerThis example shows how to search for parts of a string.
print( utf8.find( "Hello MTA User", "User" ) ) -- 11, 14 print( utf8.find( "Hello MTA User", "e" ) ) -- 2, 2 print( utf8.find( "Hello MTA User", "e", 3 ) ) -- 13, 13 print( utf8.find( "Привет Привет", "%s" ) ) -- 7, 7 print( utf8.find( "Привет Привет", "%s", 1, true ) ) -- nil -- Comparsion of utf8.find and string.find local startpos, endpos = utf8.find( "Привет", "и" ) print( startpos, endpos ) -- 3, 3 local startpos, endpos = string.find( "Привет", "и" ) print( startpos, endpos ) -- 5, 6
See Also
- utf8.byte
- utf8.char
- utf8.charpos
- utf8.escape
- utf8.find
- utf8.fold
- utf8.gmatch
- utf8.gsub
- utf8.insert
- utf8.len
- utf8.lower
- utf8.match
- utf8.ncasecmp
- utf8.next
- utf8.remove
- utf8.reverse
- utf8.sub
- utf8.title
- utf8.upper
- utf8.width
- utf8.widthindex