'-' has a special meaning as a pattern item. You can either escape
it with %- or use the optional fourth parameter to string.find that
turns off pattern matching:
> = string.find(a, '%-%-')
17 18
> = string.find(b, '%-%-')
nil
> = string.find(a, "--", 1, true)
17 18
> = string.find(b, "--", 1, true)
nil
peterhickman schreef:
I am trying to do the following:
a = 'this line has a -- comment'
b = 'this line does not'
print(string.find(a,"--"))
print(string.find(b,"--"))
but in both cases the results are
1 0
1 0
how do I match "--" in a string?
--
Fear is Money