1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

RubyでUnicode文字列をもとに戻す方法

Last updated at Posted at 2022-12-06

概要

RubyでUnicodeを普通の文字列に戻す

経緯

スクレイピングの方を実施していて、よし取得できた!と思ったらunicode形式のもので簡単に戻せるかなと思ったのですが少し苦戦したので次回以降同じことがあってもすぐ解決できるように記事にした。

だめだったこと

通常のエンコード系メソッドはだめだった

"文字列".encode(Encoding::UTF_8)

とか

成功したコマンド

"文字列".gsub(/\\u([\da-fA-F]{4})/) { [$1].pack('H*').unpack('n*').pack('U*') }

\u3054\u3063\u3064\u3048\u3048\u672c\u8217 CIAL\u6a2a\u6d5c\u5e97
↓
ごっつええ本舗 CIAL横浜店

どなたかの役に立てば幸いです

1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?