ComputerCraft Forums

ComputerCraft => Programs => Topic started by: Flexico on Nov 13, 2025, 05:45 AM

Title: String.find( always returns 1
Post by: Flexico on Nov 13, 2025, 05:45 AM
I'm not sure what's going on, but I keep trying to get the location of a decimal point in a string, and it always return "1" no matter where it is.
string.find("123.456", ".") should return 4, but it returns 1. I tried lots of different number strings, and it's always 1.
Title: String.find( always returns 1
Post by: SquidDev on Nov 13, 2025, 08:19 AM
string.find uses Lua patterns by default, with "." being the pattern that matches anything. You either need to escape the pattern (use "%."), or pass in the flag to use plain strings, rather than pattern matching (string.find("123.456", ".", nil, true)). See https://www.lua.org/manual/5.4/manual.html#pdf-string.find for more info.
Title: String.find( always returns 1
Post by: Flexico on Nov 13, 2025, 08:28 AM
Oooohh, thank you!