Search code examples
rubyoctal

remove/replace octal escapes from html


I have octal escapes in my html(stored as a string), which displays on the browser as �.

eg:- "Thanks for the update\205.nt"

Is there a way to remove these from the string or make it render properly on the browser?


Solution

  • blunt solution :

    "Thanks for the update\205".encode('ascii', :invalid => :replace, :replace => "")
    =>"Thanks for the update"
    

    see String#encode for a more subtle approach