When you use string.find, it returns the start and end index of where in the string your pattern was found. So, 11 is really 1, 1 as the data[1] and data[1] are the start and end index of the first character in your string. This brings me to my next point: string.find uses patterns, so the . is actually an operator for 'any character' as far as lua is concerned. If you're looking for the period (.), then you need to do what is called "escaping" the pattern and trying '%.' as your pattern (escaping any pattern is done by using the % sign before the character you're looking for).
Here's an example which returns the number of times that a period appears in your string.
local data = "test.rubikscuber1022.bentallea"
local occurrences = 0
-- Finds every occurrence of a period in the string 'data'.
for occurrence in data:match ("%.") do
-- Since the only time the body of this loop is executed is when
-- a period was found, we can safely increase the found number
-- of occurrences of periods in our string.
occurrences = occurrences + 1
end
This is a version using string.find:
local data = "test.rubikscuber1022.bentallea"
local occurrences = 0
local startIndex = data:find ("%.")
local moreOccurrences = startIndex ~= nil -- Whether or not the there are more periods still to find.
while moreOccurrences do
startIndex = data:find ("%.", startIndex + 1)
moreOccurrences = startIndex ~= nil
end
Here is the lua.org tutorial on patterns.
Edited by Grim Reaper, 16 December 2013 - 12:59 AM.