m
Move page script moved page API strsplit to WoW:API strsplit without leaving a redirect
No edit summary |
m (Move page script moved page API strsplit to WoW:API strsplit without leaving a redirect) |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 8: | Line 8: | ||
== Arguments == | == Arguments == | ||
;delimiter : String - Characters (bytes) that will be interpreted as delimiter characters (bytes) in the string. | |||
;subject : String - String to split. | |||
;pieces : Number (optional) - Maximum number of pieces to make (the "last" piece would contain the rest of the string); by default, an unbounded number of pieces is returned. | |||
== Returns == | == Returns == | ||
<!-- List each return value, together with its type --> | <!-- List each return value, together with its type --> | ||
A list of strings. Not a table. | A list of strings. Not a table. If the delimiter is not found in the subject string, the whole subject string will be returned. | ||
== Example == | == Example == | ||
| Line 41: | Line 37: | ||
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. | ||