Posted 09 June 2013 - 04:42 PM
Hello guys!
While working on a project, I found that a function seems to give some pretty strange results. I have tested this function in other programs allowing Lua, and the function worked perfect there. Though here… noep.
So, the function below will find the value of a parameter, like the ones in URLs: "somesite.blah?param1=1&param2=test&param3=ect" and can be seen here:
function getParam(str, param)
local retVal = ""
if str:find(param .. "=") then
for i = str:find(param .. "=") + #param + 1, #str do
if str:sub(i, i) == "&" then
break
else
retVal = retVal .. str:sub(i, i)
end
end
end
return retVal
end
Any idea why this might be the case? I tried adding tons of prints and tests.. When I did print(str:sub(str:find("action="))) in a string including "action=", it gave me a part of the string that was… deeper into the string than what was expected.
- As
While working on a project, I found that a function seems to give some pretty strange results. I have tested this function in other programs allowing Lua, and the function worked perfect there. Though here… noep.
So, the function below will find the value of a parameter, like the ones in URLs: "somesite.blah?param1=1&param2=test&param3=ect" and can be seen here:
function getParam(str, param)
local retVal = ""
if str:find(param .. "=") then
for i = str:find(param .. "=") + #param + 1, #str do
if str:sub(i, i) == "&" then
break
else
retVal = retVal .. str:sub(i, i)
end
end
end
return retVal
end
Any idea why this might be the case? I tried adding tons of prints and tests.. When I did print(str:sub(str:find("action="))) in a string including "action=", it gave me a part of the string that was… deeper into the string than what was expected.
- As