Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How convert string in Ruby

Tags:

string

ruby

Lets say we have the string '\342\200\231' (same as "\\342\\200\\231"). What is a quick way to convert this string to "\342\200\231" (same as Unicode character)?

like image 606
taro Avatar asked Jun 14 '26 01:06

taro


1 Answers

Proposal:

s.gsub(/\\(\d{3})/) { $1.oct.chr }

It depends on what assumptions you can make about your input.

like image 91
undur_gongor Avatar answered Jun 17 '26 03:06

undur_gongor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!