title: How to iterate through a string in Lua and get individual pieces
body: <p>I have a string:</p>
  
  <pre><code>line="123 123 test testing"
  </code></pre>
  
  <p>and I want to go through the pieces separated by space and check to see if each piece (123, 123, test, testing) matches a pre-determined sequence.</p>
  
  <p>I know how to tokenize a string:</p>
  
  <pre><code>for token in string.gmatch(line,'%w+') do
      print (token)
  end
  </code></pre>
  
  <p>I am not sure however how to iterate through each piece one by one and compare to my variable, <code>local var</code>.</p>
  
  <p>Basically I want to be able to get each piece of the string, compare to variable <code>var</code>'s contents.</p>
  
  <p>Here is a psudo-code:</p>
  
  <pre><code>Read file line by line { 
      Split every line by space (each line is in this format 123 456 string string) 
      Var1="123" 
      Var2="456" 
      If first token of the line= var1 then 
              If second token of the line=var2 then 
                      Print the line 
              End 
      End 
      } 
  </code></pre>