String.find( always returns 1

Started by Flexico, Today at 05:45 AM

Previous topic - Next topic

Flexico

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.

SquidDev

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.
GitHub | CC:Tweaked: A ComputerCraft fork | Plethora: A peripheral mod

Flexico