Difference between revisions of "String.find"

From GiderosMobile
m (formatting)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
 
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/string|string]]<br/>
 
'''<translate>Class</translate>:''' [[Special:MyLanguage/string|string]]<br/>
=== <translate>Description</translate> ===
 
<translate>Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.
 
  
 +
=== Description ===
 +
Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.
  
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.</translate>
+
If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.
 
<source lang="lua">
 
<source lang="lua">
 
(numbers) = string.find(s,pattern,init,plain)
 
(numbers) = string.find(s,pattern,init,plain)
 
</source>
 
</source>
=== <translate>Parameters</translate> ===
+
 
 +
=== Parameters ===
 
'''s''': (string) <translate>string where to find a pattern</translate> <br/>
 
'''s''': (string) <translate>string where to find a pattern</translate> <br/>
 
'''pattern''': (string) <translate>pattern to find</translate> <br/>
 
'''pattern''': (string) <translate>pattern to find</translate> <br/>
 
'''init''': (number) <translate>index where to start searching for pattern</translate> '''optional'''<br/>
 
'''init''': (number) <translate>index where to start searching for pattern</translate> '''optional'''<br/>
 
'''plain''': (bool) <translate>if true, then it simply matches substring without any special symbols (default = false)</translate> '''optional'''<br/>
 
'''plain''': (bool) <translate>if true, then it simply matches substring without any special symbols (default = false)</translate> '''optional'''<br/>
=== <translate>Return values</translate> ===
+
 
 +
=== Return values ===
 
'''<translate>Returns</translate>''' (numbers) <translate>indexes of occurrence of the pattern or nil</translate><br/>
 
'''<translate>Returns</translate>''' (numbers) <translate>indexes of occurrence of the pattern or nil</translate><br/>
  
 
{{String}}
 
{{String}}

Revision as of 03:09, 24 August 2020

Available since: Gideros 2011.6
Class: string

Description

Looks for the first match of pattern in the string s. If it finds a match, then find returns the indices of s where this occurrence starts and ends; otherwise, it returns nil. A third, optional numerical argument init specifies where to start the search; its default value is 1 and can be negative. A value of true as a fourth, optional argument plain turns off the pattern matching facilities, so the function does a plain "find substring" operation, with no characters in pattern being considered "magic". Note that if plain is given, then init must be given as well.

If the pattern has captures, then in a successful match the captured values are also returned, after the two indices.

(numbers) = string.find(s,pattern,init,plain)

Parameters

s: (string) string where to find a pattern
pattern: (string) pattern to find
init: (number) index where to start searching for pattern optional
plain: (bool) if true, then it simply matches substring without any special symbols (default = false) optional

Return values

Returns (numbers) indexes of occurrence of the pattern or nil