This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Geforce Fan's profile picture

Unable to string.find for "[[" - CC version 1.63

Started by Geforce Fan, 15 February 2015 - 07:27 PM
Geforce Fan #1
Posted 15 February 2015 - 08:27 PM
Bug:
When trying to string,find for [[ , it will give you:
Lua:1: vm error: java.lang.arrayIndexOutOfBoundsException: 2
What I did:
f=string.find("[[]]","[[")
It happens any time you search for [[ , though. Screenies aren't really necessary here.
edit: also, it happens if you search for "=[[". It gives the same error, but a 3 rather than 2
doubleedit: no, it errors any time you find "[" using string.find in a string.
Edited on 15 February 2015 - 07:35 PM
SquidDev #2
Posted 15 February 2015 - 08:39 PM
Looking at string patterns, you can see that [ and ] serve a similar purpose to that in regexes.

You can pass an optional 4th argument to string.find which is plain. So you would want to have:


-- Find [[ in [[]] from position 1, without using Lua patterns
string.find("[[]]", "[[", 1, true)

This isn't a bug and is the correct behaviour for Lua.
Lignum #3
Posted 15 February 2015 - 09:12 PM
You can also prefix the symbol with a percent sign if you prefer.

string.find("[[]]", "%[%[")
Geforce Fan #4
Posted 15 February 2015 - 10:18 PM
Oh. Thank you.
Lyqyd #5
Posted 16 February 2015 - 03:24 PM
Moved to Ask a Pro.