Check if String contains commas

1
local t = "Hello, World"
local v = "Hello World"

I would like to know how to check if a string contains commas ...

    
asked by anonymous 21.06.2015 / 15:48

1 answer

3

You can use the find

str = "Hello, World"
if string.find(str, ",") then
  print ("Encontrou virgula.")
else
  print ("Não encontrou virgula.")
end

If the search pattern is found the function returns the position (start and end) within the string where it was found.

> = string.find("Hello Lua user", "Lua")
7       9
> = string.find("Hello Lua user", "banana")
nil
    
21.06.2015 / 16:14