whiteSpace = 0
foo = "foo bar"
for i = 1, #foo do
if (string.sub(foo, i, i) == "%") then
whiteSpace = whiteSpace + 1
end
end
print(whiteSpace)
I'm trying to loop through this string in each character, check if it is whitespace. If the character is whitespace, I want to increment the whiteSpace variable and output it at the end. But for some reason when I execute it, it always returns 0, even though there is clearly whitespace within the foo string.
I've used "%", "%s" and "" with no avail. Pretty clueless right now.