Jump to content




Finding a character in string


  • You cannot reply to this topic
2 replies to this topic

#1 areuz

  • Members
  • 11 posts

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

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 09 December 2015 - 10:37 PM

"." is a special character which matches everything. If you want a period, use "%." instead.

Edited by KingofGamesYami, 09 December 2015 - 10:38 PM.


#3 areuz

  • Members
  • 11 posts

Posted 10 December 2015 - 12:06 AM

View PostKingofGamesYami, on 09 December 2015 - 10:37 PM, said:

"." is a special character which matches everything. If you want a period, use "%." instead.

Thank you, such a stupid mistake -_-.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users