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
Post a Comment