I'm trying to figure out how I can find a certain word in a sentence, and then return the position of the first letter in the string.

I can't figure out how to loop from the first letter to the last in W while still looking at S

S = String W = Word My problem is on line 7 of this script

function GetWordPosition(S,W)
	S=S:lower()
	W=W:lower()
	local Pos=nil
	print(S,W)
	for i=1,#S do
		if S:sub(i,i)==W:sub() then --Right here
			local Found=true
			local b=false
			for k=i,i+#W do
				if not b then
					if not S:sub(k,k)==W:sub(k,k) then
						Found=false
						b=true
					end
				end
			end
			if Found then
				Pos=i
				break
			end
		end
	end
	return Pos
end