[MacRuby-devel] Scanning Unicode strings for non-ascii characters

Robert Schaaf rwschaaf at comcast.net
Tue Mar 3 18:30:09 PST 2009


Well, my medication has finally worn off, and I came up with this:

a_string.tr('^ -~', ' ')  Any comments on efficiency?

God bless ascii for being contiguous. All this is to clean up  
imperfectly mapped EBCDIC (eeeww!)

Thanks for the suggestions.

Bob Schaaf

On Mar 3, 2009, at 10:34 AM, Manfred Stienstra wrote:

> On Mar 3, 2009, at 4:18 PM, Rich Morin wrote:
>
>> It looks to me like this is a solution for a different problem;
>> that is, discarding characters outside of the specified range.
>> Also, do we want to map newlines, etc?  Anyway, irb sez:
>
> Oops, I misread that. Yeah, gsub is probably faster.
>
>  string.unpack('U*').map { |c| (0x20..0x7e).include?(c) ? c :  
> 32 }.pack('U*')
>
> Anyway, just throwing out characters doesn't seem like a likely use- 
> case anyway.
>
> Manfred
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20090303/42ac8285/attachment.html>


More information about the MacRuby-devel mailing list