From: "Pablo Q." Date: 2008-10-09T01:34:54+09:00 Subject: Re: how to remove strange characters ------=_Part_71914_30985785.1223483821268 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline what do you think doing something like this? class String def remove_nonascii(replacement) n=self.split("") self.slice!(0..self.size) n.each{|b| if (b[0].to_i< 32 || b[0].to_i>124) then self.concat(replacement) elsif [34,35,37,42,43,44,45,47,60,61,62,63,91,92,93,94,96,123].include?(b[0].to_i) self.concat(replacement) else self.concat(b) end } self.to_s end end "Fatal injury or ruin:\223Hath some fond lover tic'd thee to thybane?\224\342\200\246".remove_nonascii('+') => "Fatal injury or ruin:+Hath some fond lover tic'd thee to thybane+++++" how you can see, it made the replacement with char '+'. 2008/10/8 Li Chen > Hi Stephen and others, > > Iconv only works for some characters. It doesn't work for the following > scripts. > > Any idea? > > Thanks, > > Li > > > C:\Users\Alex>irb > irb(main):001:0> require 'iconv' > => true > irb(main):002:0> string1="Fatal injury or ruin:\223Hath some fond lover > tic'd thee to thy bane?\224 > \342\200\246" > => "Fatal injury or ruin:\223Hath some fond lover tic'd thee to thy > bane?\224\342\200\246" > irb(main):003:0> puts > Iconv.iconv('ASCII//TRANSLIT','utf-8',string1).to_s > Iconv::IllegalSequence: "\223Hath some fond "... > from (irb):3:in `iconv' > from (irb):3 > irb(main):004:0> > > > > > > -- > Posted via http://www.ruby-forum.com/. > > -- Pablo Q. ------=_Part_71914_30985785.1223483821268--