Reputation: 13
local num = string.find("i want this to work --", "--")
return num
So this piece of code should return 21 but its actually returning 1
What am I doing wrong?
Upvotes: 0
Views: 153
Reputation: 5544
-
is a special character in Lua patterns. To do a literal match, your second argument to string.find
needs to be '%-%-'
.
Alternatively, if you don't want to deal with pattern semantics, you can pass a 4th argument of true
to tell string.find
to take the second argument as a literal string instead of as a pattern:
string.find("i want this to work --", "--", 1, true)
Upvotes: 2