Strings

Why isn’t is this working.

function setup()
    str = ",?.!()"
    i = string.find(str,"(")
    print(i)
end

This is the error: error: [string “function setup()…”]:3: unfinished capture

@Saurabh try this:

function setup()
    str = ",?.!()"
    i = string.find(str,"(", 1, true)
    print(i)
end

```

Oh thanks it worked. But what exactly does the fourth parameter mean. I saw the reference and it says something about captures and plain operation can you explain what they are?

Thanks @dave1707 understood.

You could also change it to be: i = string.find(str, "%(")

http://www.lua.org/pil/20.2.html and http://lua-users.org/wiki/PatternsTutorial are the top two hits in a search for “lua patterns”.

@Saurabh There are magic characters ^$()%.[]*±? which have a special meaning when used with string.find. The fourth parameter “true” means that string.find will use those as plain characters and treat them just like any other character.

@Jordan wouldn’t that search for “%(” instead of just “(”

No, % is one of the magic characters that does something special

@JakAttak is there any place where I can find what the magic characters do or do all of them do the same thing(which is highly improbable)?

Edit: Thanks @Andrew_Stacey.

Thanks. Understood it perfectly now.