Lore archive · Warcraft Wiki, 2023 dump
API strsplit
Last wiki revision 2022-07-21
Splits a string using a delimiter. s1, s2, ... = strsplit | string.split(delimiter, str [, pieces]) chunks = strsplittable(delimiter, str [, pieces])
- delimiter: - Characters (bytes) that will be interpreted as delimiter characters (bytes) in the string.
- str: - String to split.
- pieces: - 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.
- s1, s2, ...: - Returns a variable amount of string variables.
- chunks: - Returns an array of strings.
Note that strsplit uses a raw string as delimited, not a pattern, so it's not particularily well-suited for e.g. commandline arguments, where it should be ok to use multiple spaces. To extract whitespace-separated arguments, you can use e.g. local tbl = {} for v in string.gmatch(" this has lots of space ", "[^ ]+") do tinsert(tbl, v) 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"
N.B. 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.
Source
https://warcraft.wiki.gg/wiki/API_strsplit · retrieved 2023-11-13 · CC BY-SA 4.0
Converted from wikitext with templates, tables and images removed, so some sentences may be missing values.
This archive predates WoW: Forever. For collected gameplay facts see the Forever database. Search the archive.