Get part of a string

Verified
Added by iNTERFACEWARE

Use string.sub() to return part of a string, by specifying the start and end positions

Source Code
   -- get the first character
   local s = 'Frida'
   local sub = s:sub(1,1)
   
   -- get the third character
   local s = 'Frida'
   local sub = s:sub(3,3)
   
   -- get characters 2 to 4
   local s = 'Frida'
   local sub = s:sub(2,4)
   
   -- get the all characters from 3 onwards
   local s = 'Frida'
   local sub = s:sub(3)
Description
Use string.sub() to return part of a string, by specifying the start and end positions
Usage Details

Use string.sub() to return a substring from a string. The substring returned is specified by using start and end positions, if the end position is omitted the remainder of the string (from the start) is returned.

How to use the snippet:

  • Paste the code into your script
  • Inspect the annotations to see how it works