Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将以下已弃用的 ruby 1.8 代码转换为 ruby 1.9 代码?
invalid_chars_stripper = Iconv.new('UTF-8//IGNORE', 'UTF-8') invalid_chars_stripper.iconv(body + ' ')[0..-2]
谢谢。
这应该有效:
bad_str = "po#{0xFF.chr}ta#{0xFAFAFA.chr}to" #=> "po?ta?to" clean_str = bad_str.encode("UTF-8", {:replace=>""}) #=> "potato"