WoWInterface - View Single Post - Lua string parsing
View Single Post
11-11-05, 04:18 PM   #3
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Jun 2005
Posts: 90
If you're going for something that's quick+easy to enter, you might want to skip the comma separated list idea -- it's kind of programmerish ya know? Here's a little function that just grabs all the numbers out of a string. Some mods seem to be overly picky with chat command syntax. (Flexbar comes to mind...) People might like it if your mod is ultra lazy with the chat syntax.

function get_numbers(t)
    local w = { }
    for x in string.gfind(t, "(%d+)") do
	table.insert(w, x)
    return w

local n = get_numbers("  1 , 2,3,	4 5-6 ")

print(n[1], n[2], n[3]) -- print first 3 numbers
print(table.concat(n, ", ") .. "\n") -- print all the numbers found
  Reply With Quote