Utf8.sub: Difference between revisions

From GiderosMobile
No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Available since:''' Gideros 2016.06<br/>
'''Available since:''' Gideros 2016.06<br/>
'''Class:''' [[utf8]]<br/>
=== Description ===
=== 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.
Returns the substring of ''s'' that starts at ''i'' and continues until ''j''; ''i'' and ''j'' can be negative.
If, after the translation of negative indices, i is less than 1, it is corrected to 1. If j is greater than the string length, it is corrected to that length. If, after these corrections, i is greater than j, the function returns the empty string.</translate>
<syntaxhighlight lang="lua">
<source lang="lua">
(string) = utf8.sub(s,i,j)
(string) = utf8.sub(s,i,j)
</source>
</syntaxhighlight>
 
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''.
 
If, after the translation of negative indices, ''i'' is less than 1, it is corrected to 1. If ''j'' is greater than the string length, it is corrected to that length.
 
If, after these corrections, ''i'' is greater than ''j'', the function returns the empty string.
 
=== Parameters ===
=== Parameters ===
'''s''': (string) <translate></translate> <br/>
'''s''': (string) string<br/>
'''i''': (number) <translate></translate> <br/>
'''i''': (number) start at position<br/>
'''j''': (number) <translate></translate> '''optional'''<br/>
'''j''': (number) end at position '''optional'''<br/>
 
=== Return values ===
=== Return values ===
'''Returns''' (string) <translate>substring of s that starts at i and continues until j</translate><br/>
'''Returns''' (string) substring of s that starts at i and continues until j<br/>
 
=== Example ===
<syntaxhighlight lang="lua">
local in_str = "Hélène"
local out_str = utf8.sub(in_str, 1)
</syntaxhighlight>
 
{{Utf8}}

Latest revision as of 19:36, 1 December 2023

Available since: Gideros 2016.06
Class: utf8

Description

Returns the substring of s that starts at i and continues until j; i and j can be negative.

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

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.

If, after the translation of negative indices, i is less than 1, it is corrected to 1. If j is greater than the string length, it is corrected to that length.

If, after these corrections, i is greater than j, the function returns the empty string.

Parameters

s: (string) string
i: (number) start at position
j: (number) end at position optional

Return values

Returns (string) substring of s that starts at i and continues until j

Example

local in_str = "Hélène"
local out_str = utf8.sub(in_str, 1)