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

Finding a character in string

Started by areuz, 09 December 2015 - 08:43 PM
areuz #1
Posted 09 December 2015 - 09:43 PM
If I understand correctly, string.find(string, char) works by going over each character (or set of characters) of the string and compares it/them with the char that it was given.
So, by this logic, this should work:


local var_time = tostring(os.time())
print(var_time)
print(string.find(var_time, "."),";")

--[[
The final form should be this:
print(string.sub(var_time, 1, string.find(var_time, ".") - 1)
--]]

For some reason, print(var_time) returns a correct form of <0.000; 24.000) but the find command returns a value of 1, although the dot is clearly in the position of either 2 or 3.
Am I missing something with the os.time return value?

http://prntscr.com/9cawf9 - Screenshot, to better visualize what I'm seeing
KingofGamesYami #2
Posted 09 December 2015 - 10:37 PM
"." is a special character which matches everything. If you want a period, use "%." instead.
Edited on 09 December 2015 - 09:38 PM
areuz #3
Posted 10 December 2015 - 12:06 AM
"." is a special character which matches everything. If you want a period, use "%." instead.

Thank you, such a stupid mistake -_-/>.