Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
WoW
Talk
English
Views
Read
Edit
History
More
Search
Navigation
Home
Random page
Help using wiki
Editions
for WoW
for WildStar
for Solar2D
Documentation
for WoW
for WildStar
Reference
WoW
⦁ FrameXML
⦁ AddOns
⦁ API
⦁ WoW Lua
WildStar
⦁ AddOns
⦁ API
⦁ WildStar Lua
Engine
Tools
What links here
Related changes
Special pages
Page information
Site
Recent Changes
Editing
WoW:API strsplit
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{wowapi}} __NOTOC__ <!-- Describe the purpose of the function, exhausting detail can be saved for a later section --> Splits a string using a delimiter (optionally: into a specified number of pieces) <!-- List return values and arguments as well as function name, follow Blizzard usage convention for args --> s1, s2, s3 ... sn = strsplit("delimiter", "subject"[, pieces]) == 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 == <!-- List each return value, together with its type --> 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 == <!-- If it helps, include an example here, though it's not required if the usage is self-explanatory --> local a, b, c = strsplit(" ", "a b c d", 3) <big>'''Result'''</big> <!-- If it helps, include example results here, though they are not required. You're allowed to cheat liberally since WoW isn't a command line language. --> a = "a" b = "b" c = "c d" == Details == Again, note that the return from strsplit is a list of values, not a table. To get a table, use e.g.: local tbl = { strsplit(delimiter, subject) } Also 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" 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.
Summary:
Please note that all contributions to AddOn Studio are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
AddOn Studio Wiki:Copyrights
for details).
Submissions must be written by you, or copied from a public domain or similar free resource (see
AddOn Studio Wiki:Copyrights
for details).
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Apinav
(
edit
)
Template:Editlink
(
edit
)
Template:Tocright
(
edit
)
Template:Wowapi
(
edit
)