Difference between revisions of "String.sub"

From GiderosMobile
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[string]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/string|string]]<br/>
+
 
=== <translate>Description</translate> ===
+
=== Description ===
<translate>Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.</translate>
+
Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(string) = string.sub(s,i,j)
 
(string) = string.sub(s,i,j)
</source>
+
</syntaxhighlight>
=== <translate>Parameters</translate> ===
+
 
'''s''': (string) <translate>string to get substring from</translate> <br/>
+
=== Parameters ===
'''i''': (number) <translate>start index of substring</translate> <br/>
+
'''s''': (string) string to get substring from<br/>
'''j''': (number) <translate>index of the last character of substring</translate> '''optional'''<br/>
+
'''i''': (number) start index of substring<br/>
=== <translate>Return values</translate> ===
+
'''j''': (number) index of the last character of substring '''optional'''<br/>
'''<translate>Returns</translate>''' (string) <translate>substring</translate><br/>
+
 
 +
=== Return values ===
 +
'''Returns''' (string) substring<br/>
 +
 
 +
=== Example ===
 +
<syntaxhighlight lang="lua">
 +
local mynme = "nme01"
 +
print(string.sub(mynme, 1, 3)) -- nme
 +
-- or this
 +
print(mynme:sub(1, 3)) -- nme
 +
</syntaxhighlight>
  
 
{{String}}
 
{{String}}

Latest revision as of 15:33, 13 July 2023

Available since: Gideros 2011.6
Class: string

Description

Returns the substring of s that starts at i and continues until j; i and j can be negative. If j is absent, then it is assumed to be equal to -1 (which is the same as the string length). In particular, the call string.sub(s,1,j) returns a prefix of s with length j, and string.sub(s, -i) returns a suffix of s with length i.

(string) = string.sub(s,i,j)

Parameters

s: (string) string to get substring from
i: (number) start index of substring
j: (number) index of the last character of substring optional

Return values

Returns (string) substring

Example

local mynme = "nme01"
print(string.sub(mynme, 1, 3)) -- nme
-- or this
print(mynme:sub(1, 3)) -- nme