2 Replies Latest reply on Dec 24, 2015 11:28 PM by kimaldis

    lua, split string

    kimaldis Level 1

      This is almost embarrassing to ask about but I'm stuck. I'm trying to split a string at whitespace. I'm broadly assuming that string.gmatch() returns an array, which it appears to do in the loop example below. However if I try and grab an element from the return value it throws up an error, telling me it's a function. Can anyone help:?


      local example = "an example string"
      -- works as expected.
       for i in string.gmatch(example, "%S+") do
      -- tells me s is a function
      Debug.logn( string.gmatch( example, "%S+" ) )
      -- tells me I'm trying to index a function value
      Debug.logn( s[1] )