简体   繁体   中英

Removing Junk Characters from Ruby String

I am trying to clean up a string that I get from a website using mechanize

here is an except from the string with the junk characters

"Mountain</b></a><br>ΓÇÄ1hr&nbsp;39minΓÇÄΓÇÄ - Rated&nbsp;PGΓÇÄΓÇÄ - Action/Adventure/Science&nbsp;fictionΓÇÄΓÇÄ - EnglishΓÇÄ - <a href="

Does any one know where they characters come from and how I can replace them with spaces? How does ruby handle the encoding of characters?

Those characters look like they might be appearing as the result of a UTF-8 encoding problem. I recommend reading Joel's excellent article The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) which will explain UTF-8 encoding and how to handle it in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM