Type Function Library string.* Return value String Revision Release 2024.3703 Keywords string, sub, substring See also string.gsub() String
Returns a substring (a specified portion of an existing string).
string.sub( s, i [, j] ) s:sub( i [,j] )
String. The string.
Number. Index of the start of the substring (character position).
Number. Index of the end of the substring (inclusive). If not specified, the substring ends at the end of the string.
local s = "Hello Corona user" print( s:sub( 7 ) ) --> Corona user print( s:sub( 7, 9 ) ) --> Cor print( s:sub( -11 ) ) --> Corona user print( s:sub( -11, 12 ) ) --> Corona print( string.sub( "Hello Corona user", -11, -6 ) ) --> Corona