Sub

From OxeyeWiki

Revision as of 23:09, 8 March 2009 by Jeb (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

WChar:sub(start[, end])

This method will create a substring of the text object. There are several ways of using the method:

  1. One parameter bigger than 0. This will create a substring from 'start' (inclusive) to the end of the string.
  2. One parameter smaller than 0. This will create a substring 'start' characters from the end, to the end.
  3. Two paramters both bigger than 0. This will create a substring from 'start' (inclusive) to 'end' (inclusive).
  4. Two parameters, with 'start' smaller than 0 and 'end' bigger than 0. This will create a substring that begins from the end, using 'start' as an offset, up to 'end' (counting from the beginning of the string).
  5. Two parameters, with 'start' bigger than 0 and 'end' smaller than 0. Again, 'start' will be the starting position (inclusive) and 'end' will count from the end of the string.
  6. Two paramters both smaller than 0. Counts both 'start' and 'end' from the end of the string.
Parameter Expected Type Description
start An integer asdf
Returns

Returns a new WChar object containing the substring. The string will be empty if the parameters are incorrect.

Daisymoon GUI Lib

Example


   local text = WChar("abc123")
   text:sub(1)      -- returns "abc123"
   text:sub(2)      -- returns "bc123"
   text:sub(4)      -- returns "123"
   text:sub(0)      -- returns "abc123" (note: may change in future implementations)
   text:sub(-1)     -- returns "3"
   text:sub(-3)     -- returns "123"
   text:sub(1,1)    -- returns "a"
   text:sub(1,2)    -- returns "ab"
   text:sub(1,0)    -- returns ""
   text:sub(2,3)    -- returns "bc"
   text:sub(1,-1)   -- returns "abc123"
   text:sub(1,-2)   -- returns "abc12"
   text:sub(2,-2)   -- returns "bc12"
   text:sub(-2,-1)  -- returns "23"
   text:sub(-2,1)   -- returns ""
   text:sub(-2,6)   -- returns "23"

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox