Utf8.find: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ {{Shared function}} Finds the first occurrence of the [http://lua-users.org/wiki/PatternsTutorial pattern] in the string passed. If an instance of the pattern is fo...") |
No edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 5: | Line 5: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua">int, int utf8.find ( string input, string pattern [, int startpos = 1, boolean plain = false ] )</syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''input:''' A string character sequence | *'''input:''' A string character sequence | ||
*'''pattern :''' A string match [http://lua-users.org/wiki/PatternsTutorial pattern] (you can disable pattern matching by using the optional fourth argument ''plain'') | *'''pattern:''' A string match [http://lua-users.org/wiki/PatternsTutorial pattern] (you can disable pattern matching by using the optional fourth argument ''plain'') | ||
===Optional Arguments=== | ===Optional Arguments=== | ||
{{OptionalArg}} | {{OptionalArg}} | ||
*'''startpos:''' | *'''startpos:''' An integer representing the beginning position. | ||
*'''plain:''' A boolean, if pattern matching should be turned off | *'''plain:''' A boolean, if pattern matching should be turned off | ||
Latest revision as of 14:32, 15 June 2020
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. 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
Shared
- 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