TAPL Posted November 28, 2011 Share Posted November 28, 2011 hello does any one know how to make an function that check if the string is ASCII characters or none ASCII characters? !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ if is ASCII characters then it will returned true else false.. function xxx(player,cmd,text) if isASCII(text) then outputChatBox("it's ASCII characters!",root) else outputChatBox("it's not ASCII characters!",root) end end addCommandHandler("check",xxx) function isASCII(text) ????? return true end Link to comment
12p Posted November 28, 2011 Share Posted November 28, 2011 Using a table containing all the ASCI character and using string.find inside a "for" , would do the job. Link to comment
BinSlayer1 Posted November 28, 2011 Share Posted November 28, 2011 What do you mean? If a string matches certain ascii code (string is a number) or what? Link to comment
arezu Posted November 28, 2011 Share Posted November 28, 2011 use one of these. function isASCII(text) for i = 1, #text do local byte = text:byte(i) if(byte < 33 or byte > 126)then return false end end return true end function isASCII(text) -- used "\" before '"' as an escape char, otherwise it wont work. local asciiTable = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" for i = 1, #text do if not string.find(text, asciiTable[i], 1, true) then return false end end return true end 1 Link to comment
TAPL Posted November 29, 2011 Author Share Posted November 29, 2011 use one of these. function isASCII(text) for i = 1, #text do local byte = text:byte(i) if(byte < 33 or byte > 126)then return false end end return true end function isASCII(text) -- used "\" before '"' as an escape char, otherwise it wont work. local asciiTable = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~" for i = 1, #text do if not string.find(text, asciiTable[i], 1, true) then return false end end return true end The first code works Thanks for help 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