Drakath Posted May 16, 2014 Share Posted May 16, 2014 Is it possible to remove non ASCII characters from a text, if yes then how? Link to comment
Karuzo Posted May 16, 2014 Share Posted May 16, 2014 You could try to use the string.* functions. Link to comment
codeluaeveryday Posted May 16, 2014 Share Posted May 16, 2014 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
ixjf Posted May 16, 2014 Share Posted May 16, 2014 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
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