character encoding - Invalid Byte Sequence In UTF-8 Ruby -


i have string "abce\xc3".sub("a","a"), when execute line following error.

argumenterror: invalid byte sequence in utf-8     (irb):20:in `sub'     (irb):20     /home/vijay/.rvm/rubies/ruby-2.0.0-p598/bin/irb:12:in `<main>' 

can me solve problem.

as arie answered error because invalid byte sequence \xc3

if using ruby 2.1 +, can use string#scrub replace invalid bytes given replacement character. here:

a = "abce\xc3" # => "abce\xc3"  a.scrub # => "abce�" a.scrub.sub("a","a") # => "abce�" 

Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -