Reputation: 63
Below is my piece of code
str = "abc@hotmailcom"
a = string.find(str , "@")
print(a)
My output is 4 i.e place value of "@"
But when I run the following piece of code
str = "abc@hotmailcom"
a = string.find(str , ".")
print(a)
instead of outputting "nil", the program returns the value 1.
I am new to Lua language so could anyone explain to me what is happening and how string.find() works in lua?
Upvotes: 1
Views: 668
Reputation: 560
.
is a character class for all characters in lua pattern, you have to to escape it with %
.
See Lua Patterns
> print(string.find("abc@hotmailcom", "."))
1 1
> print(string.find("abc@hotmailcom", "%."))
nil
Upvotes: 1