DJ_AM_Juicebox
asked on
Remove non-ascii chars from a String?
Hi,
Is there any java utility for removing non-ascii characters from a string? I think I can loop through each character (charAt()) which will give me its "ascii value" and if it's not in the ascii range, just wipe it. But I'm not sure what charAt() will return when I really have non-ascii characters since I've never run into that situation.
How can I do it?
The reason I need to do it is that I'm using a library which does ellipsiszing of a string, and if it encounters and non-ascii char it seems to crash, so want to clean my strings before passing them in.
Thanks
Is there any java utility for removing non-ascii characters from a string? I think I can loop through each character (charAt()) which will give me its "ascii value" and if it's not in the ascii range, just wipe it. But I'm not sure what charAt() will return when I really have non-ascii characters since I've never run into that situation.
How can I do it?
The reason I need to do it is that I'm using a library which does ellipsiszing of a string, and if it encounters and non-ascii char it seems to crash, so want to clean my strings before passing them in.
Thanks
I suppose it depends on how you're defining 'ascii' and what your original encoding
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>it is not an ascii symbol
What is an 'ascii symbol'? Is ' €' one?
What is an 'ascii symbol'? Is ' €' one?
http://forums.sun.com/thread.jspa?threadID=5370865
http://www.rgagnon.com/javadetails/java-0536.html
output = input.replaceAll([^\\p{ASC