I have strings like "ABC-DEF" and I need to split them by the "-" character and assign each of the two parts to a variable. In Ruby, I would do it like:
a, b = "ABC-DEF".split('-')
Apparently, Lua doesn't have such an easy way. After some digging, I couldn't find a short and concise way to achieve what I'm after. I mention I am a complete newbie to Lua and I need to use it in a script for Redis (so it should indeed be small, a one liner if possible).
解决方案
Use pattern matching:
a, b = string.match("ABC-DEF", "(.*)%-(.*)")
Note that - is a magic character, so it must be escaped with %.