As with many other string methods such as string.upper
, you can use split in this manner:
local x = "hello doge fans"
table.foreach(x:split(" "), print)
-- 1 hello
-- 2 doge
-- 3 fans
However, if you were to make a typo on this line and instead did x.split(" ")
, you would instead get the unexpected:
local x = "hello doge fans"
table.foreach(x.split(" "), print)
-- 1
This is unlike other string methods, which expectedly provide a helpful error:
> print(("hello").upper())
07:51:36.279 - print(("hello").upper()):1: bad argument #1 to 'upper' (string expected, got no value)
07:51:36.280 - Stack Begin
07:51:36.280 - Script 'print(("hello").upper())', Line 1
07:51:36.280 - Stack End
CC @Tiffblocks