Problem with string.find

Hi, I’ve a stange problem with the function string.find

I’ve a text file where I store my data, for each line I have a text like “Name-Description”

Before adding new item I simply check if the name is existing using the code (the user write the name in the textField “nameField”)

if (string.find(textFile,nameField.text .. "-") == nil) then -- the name doesn't exist else -- the name exist end

But I don’t know why, the program find the string nameField.text without the character “-”.
So if I have a file like “Banana-yellow fruit” and the user type “fruit”, the program find a match (it’s wrong! I want a match only if the user type “Banana”)

Why?

– Edit: If I use other character to separate name and description like “/” the program work good…I think that there is a problem with “-”

Please refer to this for special characters.  This is your problem, you will need to code this a different way not using -.

https://docs.coronalabs.com/guide/data/luaString/index.html

if (string.find(textFile,nameField.text .. "%-") == nil) then -- the name doesn't exist else -- the name exist end

Please refer to this for special characters.  This is your problem, you will need to code this a different way not using -.

https://docs.coronalabs.com/guide/data/luaString/index.html

if (string.find(textFile,nameField.text .. "%-") == nil) then -- the name doesn't exist else -- the name exist end