Monday, May 27, 2013

Lua: Using split method from the string_ext module

Due to the minimalist nature of Lua, the standard library for string does not contain commonly used methods like split. However, the module string_ext contains them. Below is a snippet on how to use the split method. The point to consider here is the module we have to import in order for the method to work correctly. Importing only the string_ext module is not enough. We have to import list and strbuf modules as well.
print(string.split("Hello World", " ")) -- outputs {1=Hello,2=World}