What is the string pattern for a space? Like, the space the spacebar types?
Is there a pattern that does JUST the spacebar?
My goal is to print each word in a sentence, but the word I'm
gets split up into I
and m
when I try "%a+"
:
for w in string.gmatch("I'm filling out a job application.", "%a+") do print(w) wait() end
I would appreciate any replys. Thanks!
I normally use a pattern trick for those things. You can also check for "not patterns".
In this case you want to match any sequence of characters which is NOT a space.
A space pattern is btw just " ". The %s pattern also matches \n (newline) and some more "white space characters"
The pattern I would use is "[^ ]+". This matches any sequence which is NOT a space. A [] pattern defines a set of characters. If this set stats with a ^ it means NOT that set. In this case we check for non-spaces.
Output:
for w in string.gmatch("I'm filling out a job application.", "[^ ]+") do print(w) -- There is no need to wait in this case. -- wait() end --[[Output: I'm filling out a job application --]]