<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>ma2</author_name>
  <author_url>https://blog.hatena.ne.jp/ma2/</author_url>
  <blog_title>ma2’s diary</blog_title>
  <blog_url>https://ma2.hatenadiary.com/</blog_url>
  <categories>
    <anon>software</anon>
  </categories>
  <description>rubyを使っていていつも困ることがあった。それは文字列に文字単位でアクセスするメソッドが無いこと。jcode.rbを取り込むことで可能になるのだけど面倒くさいし，UTF-8文字列には使えない。こんな基本的な機能はオレが気づかないだけでどっかにあるんじゃないかとずっと疑問に思っていたのだけど，先日唐突に解決しました。 具体的には正規表現クラスが文字単位の操作に対応しているので，これを使うといいのでした。 str =~ /^(.{5})/u とやれば，先頭5文字を$1で取り出せます。ちなみに最後のuはUTF-8文字列を意味していて，ruby文字列はJIS，シフトJIS，eucの3つしかサポートし…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fma2.hatenadiary.com%2Fentry%2F20040608%2Fp3&quot; title=&quot;Rubyで文字列からn文字取り出す - ma2’s diary&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2004-06-08 00:00:02</published>
  <title>Rubyで文字列からn文字取り出す</title>
  <type>rich</type>
  <url>https://ma2.hatenadiary.com/entry/20040608/p3</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
