string.find returns nil

Good Day, My string.find returns nil whenever I do this 

local himay = "beef chicken" local hiamyT = {} local po = "beef" local counter = 0 for i = 1 , string.len(himay) do print(string.sub(himay,i,i)) if string.sub(himay,i,i) == " " then local catch = tostring(string.sub(himay,0,i)) print(catch) -- shows "beef" print(string.find(testing,tostring(catch))) --Here is the Problem "catch" is not declared as string I think if string.find(testing,catch) ~= nil then --Here is the Problem"catch" is not declared as string I think counter = counter + 1 print(counter) end end end

But when I do this

local himay = "beef chicken" local hiamyT = {} local po = "beef" local counter = 0 for i = 1 , string.len(himay) do print(string.sub(himay,i,i)) if string.sub(himay,i,i) == " " then local catch = tostring(string.sub(himay,0,i)) print(catch) print(string.find(testing,po)) --It works, returns 1 4 if string.find(testing,po) ~= nil then --It works, returns 1 4 counter = counter + 1 print(counter) end end end

I don’t know why this keeps happening, please help thanks

problem solved tostring(string.sub(himay,0,i-1)) space was included

problem solved tostring(string.sub(himay,0,i-1)) space was included