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

Manfred Stienstra manfred at gmail.com
Tue Mar 3 07:34:05 PST 2009


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


More information about the MacRuby-devel mailing list