I knew there was a better way to do this, so here it is:
function findWordInString(%string, %word)
{
%word = trim(%word);
%index = striPos(" " @ %string @ " ", " " @ %word @ " ");
if(%index < 2)
return %index;
%before = getSubStr(%string, 0, %index);
return strLen(%before)-strLen(strReplace(%before, " ", ""));
}
This will do the exact same thing, but without any for loops.