Check if String contains commas

Asked

Viewed 254 times

1

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

I wonder how to check if a string contains commas...

1 answer

3


You can use the function 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
  • 1

    That’s right, I didn’t remember this string.find function! Thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.