I'm trying to get this code to work (ruby 1.8.7):
line = "abc"
"#{line}☃".encode('utf-8')[0..-2].scan(/\p{Katakana}/)
but it returns undefined method 'encode' for "abc\342\230\203":String (NoMethodError)
.
You can run the program here: http://codepad.org/nh6cAqHT
You are probably using an older version of ruby. It is available in 1.9.3 but not in 1.8.7, so check which version you're using.
1.9.3p194 :001 > line = "abc"
=> "abc"
1.9.3p194 :002 > "#{line}☃".encode('utf-8')[0..-2].scan(/\p{Katakana}/)
=> []
Works fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With