WoW:API strsplit: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 11: Line 11:
:(delimiter, subject)
:(delimiter, subject)


:;delimiter : String - Delimiter
:;delimiter : String - Delimiter (every single byte of the string will be used to split; see details)
:;subject : String - String to split
:;subject : String - String to split
:;pieces : integer - Optional argument designating the number of pieces to make.
:;pieces : integer - Optional argument designating the number of pieces to make.
Line 41: Line 41:
   tinsert(tbl, v)
   tinsert(tbl, v)
  end
  end
Additionally note that the delimiter defines all bytes that will split the string, e.g.:
strsplit("ab", "1a2b3")  -- => "1", "2", "3"
or
strsplit("ab", "1ab2")  -- => "1", "", "2"


Nota Bene:  This function does not handle embedded NUL characters ("\0") gracefully.  If you need a unique "signpost" character embedded in your strings to be split apart later, try the ASCII bell character ("\a").  This won't show up in the game, and strsplit handles it just fine.
Nota Bene:  This function does not handle embedded NUL characters ("\0") gracefully.  If you need a unique "signpost" character embedded in your strings to be split apart later, try the ASCII bell character ("\a").  This won't show up in the game, and strsplit handles it just fine.
Anonymous user