'LinKin Posted April 15, 2014 Share Posted April 15, 2014 Hello, I want to check it a string is a color code or not. I tried with string.match but it's not precise.. It's like using string.find. So if I have; local theString = "#FF0000Test" string.find(theString, "#%x%x%x%x%x%x") will return true, but it's not since the string contains the 'extension' (Test) I tried if theString == "#%x%x%x%x%x%x" then ... But it didn't work either.. function isHexCode(theString) --Which condition to put here? end Thanks. Link to comment
'LinKin Posted April 16, 2014 Author Share Posted April 16, 2014 Well ok I made this: It seems to work function isStringHexCode(theHex) local Hex = theHex:gsub("#", "") if #Hex == 6 and tonumber(Hex, 16) then return true end return false end I got another question, How can I check if the first character of the string is "#" or not? Link to comment
Bonsai Posted April 16, 2014 Share Posted April 16, 2014 string.find returns the position if there is a match, just check if its 1,1. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now