@nick the LUA code for string.gmatch()
doesn’t seem to work. I had to hard code an alternate string splitting method.
Is there a quick way to check which string and other methods are currently supported for LUA?
I would like to use something like the following from this guide:
local example = "an example string"
for i in string.gmatch(example, "%S+") do
print(i)
end
Here are the rest of the string functions from this guide:
Working:
string.byte(s [, i [, j]])
string.char(i1, i2, ...)
string.len(s)
string.lower(s)
string.upper(s)
string.reverse(s)
string.sub(s, i [, j])
Not working as expected
string.dump(function)
string.find(s, pattern [, index [, plain]])
string.format(s, e1, e2, ...)
string.gmatch(s, pattern)
string.gsub(s, pattern, replace [, n])
string.match (s, pattern [, index])
string.rep(s, n)
Test code utilized:
local theFunction = function()
return "Not the string you wanted"
end
local theString = "This is a string"
hero:say(string.byte("ABCDE") .. " - byte")
hero:say(string.char(65,66,67) .. " - char")
hero:say(string.upper(theString) .. " - upper")
hero:say(string.lower(theString) .. " - lower")
hero:say(string.len(theString) .. " - len")
hero:say(string.reverse(theString) .. " - reverse")
hero.say(string.sub(theString, 6, 9) .. " - sub")
-- Not currently working
hero:say(string.rep("Lua ",5) .. " - rep")
hero:say(string.match("I have 2 questions for you.", "%d+ %a+") .. " - match")
hero.say(string.gsub("Hello banana", "banana", "Lua user") .. " - gsub" )
hero:say("Gmatching!")
for word in string.gmatch("Hello Lua user", "%a+") do hero:say(word) end
hero:say(string.format("%s %q", "Hello", "Lua user!") .. " - format")
hero:say(string.find("Hello Lua user", "Lua") .. " - find")
hero:say(string.dump(theFunction) .. " - function")