<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>UTF-8 on Artem Yegorov</title>
    <link>https://yegorov.github.io/tags/utf-8/</link>
    <description>Recent content in UTF-8 on Artem Yegorov</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Thu, 26 Nov 2026 09:24:14 +0000</lastBuildDate>
    <atom:link href="https://yegorov.github.io/tags/utf-8/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Text encoding in Ruby</title>
      <link>https://yegorov.github.io/notes/text-encoding-in-ruby/</link>
      <pubDate>Thu, 26 Nov 2026 09:24:14 +0000</pubDate>
      <guid>https://yegorov.github.io/notes/text-encoding-in-ruby/</guid>
      <description>&lt;p&gt;If you work with text often especially when parsing scraped or external data you&amp;rsquo;ve almost certainly run into encoding issues. Typically, it goes like this: you receive text from a parser in binary encoding (ASCII-8BIT), and you need to convert it to UTF-8 for further processing.&lt;/p&gt;&#xA;&lt;p&gt;In Ruby, you&amp;rsquo;d normally just call the &lt;a href=&#34;https://docs.ruby-lang.org/en/master/String.html#method-i-encode&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;String#encode&lt;/code&gt;&lt;/a&gt; method. However, if the text contains malformed characters, you&amp;rsquo;ll hit an exception like &lt;code&gt;&#39;String#encode&#39;: &amp;quot;\xEF&amp;quot; from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)&lt;/code&gt;. To strip out the bytes that can&amp;rsquo;t be transcoded, call &lt;code&gt;encode&lt;/code&gt; with the &lt;code&gt;replace: &#39;&#39;&lt;/code&gt; option (see the example in the screenshot).&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
