You could try...
require 'iconv'
clean_str = Iconv.new('UTF-8//Ignore', 'UTF-8').iconv(messy_str)
It doesn't always work though... you might need to catch
Iconv::InvalidCharacter...
Worth a try though and has gotten me out of some of this mess with bad
source data.
On Jun 23, 2009, at 1:03 PM, Nik wrote:
>
> Hello!
>
> I use MySQL and making sure it is UTF-8 and in my view the character
> set is also UTF-8. But when I display the text whose input came from
> either an antiword.exe or WIN32OLE output of a MS Word document in a
> textarea. Text fail to show immediately after a strange character that
> shows up in rails console as \267. And I went back to Word to see what
> this is (looked it up by its position). And it is a dot sort of
> floating in middle of the line. Sort of like how they display chapters
> or whatever they call it of the Bible. like 12-7[dot]Matthrew
>
> For example:
> Rails Console:
>>> doc="This is a pipe, but \267 this is not a pipe"
> HTML:
> <p>
> This is a pipe, but
> </p>
> It just sort of STOPS rendering the rest of the text.
>
> I can't possibly ask my clients to remove that so to convenient me. I
> have been on a 38 hours hunt to try to find some solutions to it.
>
> Some says remove all [^[:print:]] matches. Which I can do and find a
> way to at least preserve the \n\r's. But then again, I do want to
> preserve also as much of the original document as possible. I mean,
> what if they use umlauts the o with " on top.
>
> Any ideas?
>
> Thank You!
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---