Jump to content

ASCII


Drakath

Recommended Posts

spent a good 20 minutes figuring it out for you, I had numerous ideas, and I ended up here:

function stripNonANSIData(str) 
    local str = tostring(str) 
    local newSTR = '' 
    for i=1, string.len(str) do 
        local theChar = str:sub(i, i) 
        local theANSINumber = string.byte(theChar) 
        if theANSINumber > 32 and theANSINumber < 127 then 
            newSTR = newSTR..theChar 
        end 
    end 
    return newSTR 
end 

^ English only rly, no arabics, no spanish poodles.

Link to comment

csmit195, your implementation doesn't take into account the characters from the range 0-32 (for instance, the space), and it iterates over each byte (unicode characters are multi-byte, that means your function will iterate between 2 and 4 times per each unicode character, rather than over each character) because string.len returns the string byte length, not the character length. You may want to check out my implementation: viewtopic.php?f=148&t=74970#p693265

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...