Jump to content

help ASCII..


TAPL

Recommended Posts

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 

:roll:

Link to comment

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 

  • Like 1
Link to comment
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 :D

Thanks for help

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...