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

Rich Morin rdm at cfcl.com
Tue Mar 3 07:18:44 PST 2009


At 12:45 +0100 3/3/09, Manfred Stienstra wrote:
> On Mar 3, 2009, at 12:37 PM, Robert Schaaf wrote:
>>    string.unpack('U*').
>>      select { |c| (0x20..0x7e).include?  (c) }.
>>      pack('U*')

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:

>> a = "abc\x0adef"
=> "abc\ndef"
>> a.gsub(/[^\x20-\x7e]/, ' ')
=> "abc def"
>> a.gsub(/[^\x00-\x7e]/, ' ')
=> "abc\ndef"

-r
-- 
http://www.cfcl.com/rdm            Rich Morin
http://www.cfcl.com/rdm/resume     rdm at cfcl.com
http://www.cfcl.com/rdm/weblog     +1 650-873-7841

Technical editing and writing, programming, and web development


More information about the MacRuby-devel mailing list