3 Mar
2009
3 Mar
'09
11:45 a.m.
On Mar 3, 2009, at 12:37 PM, Robert Schaaf wrote:
This may be obvious, but in a Unicode world it's driving me nuts. Given an arbitrary string, which may contain unicode characters, how do I replace all characters not in the range 0x20..0x7e with spaces?
This isn't really a MacRuby related question, but here you go (: string.unpack('U*').select { |c| (0x20..0x7e).include? (c) }.pack('U*') There are probably 200 other solutions, but this seems to be the easiest one. Remember that this not very fast and you probably want to use Iconv or something if your processing large pieces of text. Manfred